From 234d48c8ad07203408219b638c353a4dbd3a172a Mon Sep 17 00:00:00 2001 From: Chad Baker Date: Thu, 17 Aug 2023 11:24:57 -0600 Subject: [PATCH] added Option<...> to RustCycleElement and serde defaults to RustCycle for grade and road_type --- rust/fastsim-core/src/cycle.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/rust/fastsim-core/src/cycle.rs b/rust/fastsim-core/src/cycle.rs index 294a46ad..56087f9a 100644 --- a/rust/fastsim-core/src/cycle.rs +++ b/rust/fastsim-core/src/cycle.rs @@ -369,10 +369,10 @@ pub struct RustCycleElement { pub mps: f64, /// grade [rise/run] #[serde(alias = "cycGrade")] - pub grade: f64, + pub grade: Option, /// max possible charge rate from roadway #[serde(alias = "cycRoadType")] - pub road_type: f64, + pub road_type: Option, } #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)] @@ -603,9 +603,11 @@ pub struct RustCycle { pub mps: Array1, /// array of grade [rise/run] #[serde(alias = "cycGrade")] + #[serde(default)] pub grade: Array1, /// array of max possible charge rate from roadway #[serde(alias = "cycRoadType")] + #[serde(default)] pub road_type: Array1, pub name: String, #[serde(skip)] @@ -661,12 +663,14 @@ impl RustCycle { self.mps .append(Axis(0), array![cyc_elem.mps].view()) .unwrap(); - self.grade - .append(Axis(0), array![cyc_elem.grade].view()) - .unwrap(); - self.road_type - .append(Axis(0), array![cyc_elem.road_type].view()) - .unwrap(); + if let Some(grade) = cyc_elem.grade { + self.grade.append(Axis(0), array![grade].view()).unwrap(); + } + if let Some(road_type) = cyc_elem.road_type { + self.road_type + .append(Axis(0), array![road_type].view()) + .unwrap(); + } } #[allow(clippy::len_without_is_empty)]