thermostat/src/units.rs

38 lines
818 B
Rust
Raw Normal View History

use core::{
fmt,
ops::Div,
};
2020-05-17 06:13:52 +08:00
2020-05-17 07:23:35 +08:00
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
2020-05-17 06:13:52 +08:00
pub struct Volts(pub f64);
impl fmt::Display for Volts {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:.3}V", self.0)
}
}
impl Div<Ohms> for Volts {
type Output = Amps;
fn div(self, rhs: Ohms) -> Amps {
Amps(self.0 / rhs.0)
}
}
2020-05-17 07:23:35 +08:00
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
pub struct Amps(pub f64);
impl fmt::Display for Amps {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:.3}A", self.0)
}
}
2020-05-17 07:23:35 +08:00
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
pub struct Ohms(pub f64);
impl fmt::Display for Ohms {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:.3}Ω", self.0)
}
}