#![doc = include_str!("../README.md")]
#![forbid(unsafe_code)]
use std::fmt;
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub struct ScheduleQuantity(u64);
impl ScheduleQuantity {
#[must_use]
pub const fn from_kw(kw: u64) -> Self {
Self(kw)
}
}
impl fmt::Display for ScheduleQuantity {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}.{:03}", self.0 / 1000, self.0 % 1000)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn megawatts_preserve_every_kilowatt() {
for (kw, expected) in [
(0, "0.000"),
(1, "0.001"),
(999, "0.999"),
(1000, "1.000"),
(u64::MAX, "18446744073709551.615"),
] {
assert_eq!(ScheduleQuantity::from_kw(kw).to_string(), expected);
}
}
}