diff --git a/src/decoders/common_types/barorate.rs b/src/decoders/common_types/barorate.rs new file mode 100644 index 0000000..ba31de7 --- /dev/null +++ b/src/decoders/common_types/barorate.rs @@ -0,0 +1,43 @@ +// Copyright (c) 2023-2024 Frederick Clausen II + +// Use of this source code is governed by an MIT-style +// license that can be found in the LICENSE file or at +// https://opensource.org/licenses/MIT. + +use serde::{Deserialize, Serialize}; +use std::fmt; + +#[derive(Deserialize, Debug, Clone, PartialEq, PartialOrd, Default)] +#[serde(from = "i32")] +pub struct BaroRate { + baro_rate: i32, +} + +impl Serialize for BaroRate { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + serializer.serialize_i32(self.baro_rate) + } +} + +impl From for BaroRate { + fn from(baro_rate: i16) -> Self { + Self { + baro_rate: i32::from(baro_rate), + } + } +} + +impl From for BaroRate { + fn from(baro_rate: i32) -> Self { + Self { baro_rate } + } +} + +impl fmt::Display for BaroRate { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{} ft/min", self.baro_rate) + } +}