Added volume quantities.

This commit is contained in:
Zachary Sunforge
2024-12-12 18:59:08 -08:00
parent 59ef1e4219
commit 4c922b940b
5 changed files with 48 additions and 3 deletions

View File

@ -16,7 +16,7 @@ members = [
]
[workspace.package]
version = "0.4.1"
version = "0.4.2"
edition = "2021"
repository = "https://git.bfpower.io/BFPOWER/physical"
readme = "README.md"

View File

@ -2,6 +2,7 @@ mod irradiance;
mod resistance;
mod temperature;
mod voltage;
mod volume;
mod volume_rate;
mod pressure;
@ -12,6 +13,7 @@ pub use irradiance::*;
pub use resistance::*;
pub use temperature::*;
pub use voltage::*;
pub use volume::*;
pub use volume_rate::*;
pub use pressure::*;

View File

@ -21,7 +21,7 @@ impl <V: Value> Kelvins<V> {
}
}
//----- Deci Kelvins ----------------------------------
//----- Decikelvins ----------------------------------
quantity_type! {DeciKelvins, "dK"}
impl<V: Value> DeciKelvins<V> {

View File

@ -14,7 +14,7 @@ impl<V: Value> Volts<V> {
}
}
//----- Milli Volts ----------------------------------
//----- Millivolts ----------------------------------
quantity_type! {MilliVolts, "mV"}
impl<V: Value> MilliVolts<V> {

43
src/quantity/volume.rs Normal file
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);
}
}