-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df3d5cf
commit 159d43e
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: serde::Serializer, | ||
{ | ||
serializer.serialize_i32(self.baro_rate) | ||
} | ||
} | ||
|
||
impl From<i16> for BaroRate { | ||
fn from(baro_rate: i16) -> Self { | ||
Self { | ||
baro_rate: i32::from(baro_rate), | ||
} | ||
} | ||
} | ||
|
||
impl From<i32> 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) | ||
} | ||
} |