From 220e036ce3e5c3e76ad35c0e434f5d11a355e057 Mon Sep 17 00:00:00 2001 From: Joseph Angelo Date: Thu, 18 Jul 2024 17:49:42 -0700 Subject: [PATCH] Add optional serde support --- swiftnav/Cargo.toml | 4 ++++ swiftnav/src/coords.rs | 4 ++++ swiftnav/src/reference_frame/mod.rs | 3 +++ 3 files changed, 11 insertions(+) diff --git a/swiftnav/Cargo.toml b/swiftnav/Cargo.toml index 77204ac..20a02ba 100644 --- a/swiftnav/Cargo.toml +++ b/swiftnav/Cargo.toml @@ -14,6 +14,10 @@ rustversion = "1.0" chrono = { version = "0.4", optional = true } swiftnav-sys = { version = "^0.9.0", path = "../swiftnav-sys/" } strum = { version = "0.26", features = ["derive"] } +serde = { version = "1.0.204", features = ["derive"], optional = true } [dev-dependencies] float_eq = "1.0.1" + +[features] +serde = ["dep:serde"] diff --git a/swiftnav/src/coords.rs b/swiftnav/src/coords.rs index c37e403..2f80fd4 100644 --- a/swiftnav/src/coords.rs +++ b/swiftnav/src/coords.rs @@ -58,6 +58,7 @@ use crate::{ /// /// Internally stored as an array of 3 [f64](std::f64) values: latitude, longitude (both in the given angular units) and height above the geoid in meters #[derive(Copy, Clone, Debug, PartialEq, PartialOrd)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct LLHDegrees([f64; 3]); impl LLHDegrees { @@ -147,6 +148,7 @@ impl From for LLHRadians { /// /// Internally stored as an array of 3 [f64](std::f64) values: latitude, longitude (both in the given angular units) and height above the geoid in meters #[derive(Copy, Clone, Debug, PartialEq, PartialOrd)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct LLHRadians([f64; 3]); impl LLHRadians { @@ -238,6 +240,7 @@ impl From for LLHDegrees { /// /// Internally stored as an array of 3 [f64](std::f64) values: x, y, z all in meters #[derive(Copy, Clone, Debug, PartialEq, PartialOrd)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct ECEF([f64; 3]); impl ECEF { @@ -436,6 +439,7 @@ impl MulAssign<&f64> for ECEF { /// /// Internally stored as an array of 3 [f64](std::f64) values: N, E, D all in meters #[derive(Copy, Clone, Debug, PartialEq, PartialOrd)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct NED([f64; 3]); impl NED { diff --git a/swiftnav/src/reference_frame/mod.rs b/swiftnav/src/reference_frame/mod.rs index 4acf08a..6fdd55d 100644 --- a/swiftnav/src/reference_frame/mod.rs +++ b/swiftnav/src/reference_frame/mod.rs @@ -83,6 +83,7 @@ mod params; /// Reference Frames #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, EnumString, Display, EnumIter)] #[strum(serialize_all = "UPPERCASE")] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum ReferenceFrame { ITRF88, ITRF89, @@ -137,6 +138,7 @@ pub enum ReferenceFrame { /// the scaling is in parts per billion. We also follow the /// IERS convention for the sign of the rotation terms. #[derive(Debug, PartialEq, PartialOrd, Clone, Copy)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct TimeDependentHelmertParams { tx: f64, tx_dot: f64, @@ -216,6 +218,7 @@ impl TimeDependentHelmertParams { /// A transformation from one reference frame to another. #[derive(Debug, PartialEq, PartialOrd, Clone, Copy)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Transformation { pub from: ReferenceFrame, pub to: ReferenceFrame,