Initial proof of concept

This commit is contained in:
Zachary Levy
2025-03-09 12:13:14 -07:00
commit e06e76e46b
55 changed files with 4508 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
use crate::quantity::{Quantity, Value};
use generate_quantity::quantity_type;
use crate::quantity::MILLI;
//----- Liters ----------------------------------
quantity_type! {Liters, "L"}
impl<V: Value> Liters<V> {
#[inline]
pub fn to_milli_liters(self) -> MilliLiters<V> {
let multiplier = V::from_u16(MILLI).unwrap();
MilliLiters(self.0 * multiplier)
}
}
//----- Milliliters ----------------------------------
quantity_type! {MilliLiters, "mL"}
impl<V: Value> MilliLiters<V> {
#[inline]
pub fn to_liters(self) -> MilliLiters<V> {
let divisor = V::from_u16(MILLI).unwrap();
MilliLiters(self.0 / divisor)
}
}
// ---------------------------------------------------------------------------------------------------------------------
// ----- Tests ------------------------
// ---------------------------------------------------------------------------------------------------------------------
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn convert_u32() {
let liters: Liters<u32> = 12.liters();
let milli_liters: MilliLiters<u32> = 12_000.milli_liters();
assert_eq!(liters.0, milli_liters.to_liters().0);
assert_eq!(milli_liters.0, liters.to_milli_liters().0);
}
}