Files
physical/src/quantity/volume.rs
T
2026-04-02 12:02:35 -07:00

44 lines
1.2 KiB
Rust

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) -> Liters<V> {
let divisor = V::from_u16(MILLI).unwrap();
Liters(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);
}
}