Added volume quantities.
This commit is contained in:
@ -16,7 +16,7 @@ members = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.4.1"
|
version = "0.4.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
repository = "https://git.bfpower.io/BFPOWER/physical"
|
repository = "https://git.bfpower.io/BFPOWER/physical"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
@ -2,6 +2,7 @@ mod irradiance;
|
|||||||
mod resistance;
|
mod resistance;
|
||||||
mod temperature;
|
mod temperature;
|
||||||
mod voltage;
|
mod voltage;
|
||||||
|
mod volume;
|
||||||
mod volume_rate;
|
mod volume_rate;
|
||||||
mod pressure;
|
mod pressure;
|
||||||
|
|
||||||
@ -12,6 +13,7 @@ pub use irradiance::*;
|
|||||||
pub use resistance::*;
|
pub use resistance::*;
|
||||||
pub use temperature::*;
|
pub use temperature::*;
|
||||||
pub use voltage::*;
|
pub use voltage::*;
|
||||||
|
pub use volume::*;
|
||||||
pub use volume_rate::*;
|
pub use volume_rate::*;
|
||||||
pub use pressure::*;
|
pub use pressure::*;
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ impl <V: Value> Kelvins<V> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//----- Deci Kelvins ----------------------------------
|
//----- Decikelvins ----------------------------------
|
||||||
quantity_type! {DeciKelvins, "dK"}
|
quantity_type! {DeciKelvins, "dK"}
|
||||||
|
|
||||||
impl<V: Value> DeciKelvins<V> {
|
impl<V: Value> DeciKelvins<V> {
|
||||||
|
@ -14,7 +14,7 @@ impl<V: Value> Volts<V> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//----- Milli Volts ----------------------------------
|
//----- Millivolts ----------------------------------
|
||||||
quantity_type! {MilliVolts, "mV"}
|
quantity_type! {MilliVolts, "mV"}
|
||||||
|
|
||||||
impl<V: Value> MilliVolts<V> {
|
impl<V: Value> MilliVolts<V> {
|
||||||
|
43
src/quantity/volume.rs
Normal file
43
src/quantity/volume.rs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user