Initial proof of concept
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user