From 9fbbf0b1ce594ba8b86dda6cf1b67b0dd0662782 Mon Sep 17 00:00:00 2001 From: Zachary Sunforge Date: Thu, 2 Jan 2025 20:48:22 -0800 Subject: [PATCH] Added Pascals --- Cargo.toml | 2 +- src/quantity/pressure.rs | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 872ed09..98e5c34 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ members = [ ] [workspace.package] -version = "0.4.2" +version = "0.4.3" edition = "2021" repository = "https://git.bfpower.io/BFPOWER/physical" readme = "README.md" diff --git a/src/quantity/pressure.rs b/src/quantity/pressure.rs index af1c474..0e8b679 100644 --- a/src/quantity/pressure.rs +++ b/src/quantity/pressure.rs @@ -1,5 +1,43 @@ use crate::quantity::{Quantity, Value}; use generate_quantity::quantity_type; -//----- Kilopascal ---------------------------------- +use super::KILO; + +//----- Pascals ---------------------------------- +quantity_type! {Pascals, "Pa"} + +impl Pascals { + #[inline] + pub fn to_kilo_pascals(self) -> KiloPascals { + let divisor = V::from_u16(KILO).unwrap(); + KiloPascals(self.0 / divisor) + } +} + +//----- Kilopascals ---------------------------------- quantity_type! {KiloPascals, "kPa"} + +impl KiloPascals { + #[inline] + pub fn to_pascals(self) -> Pascals { + let multiplier = V::from_u16(KILO).unwrap(); + Pascals(self.0 * multiplier) + } +} + +// --------------------------------------------------------------------------------------------------------------------- +// ----- Tests ------------------------ +// --------------------------------------------------------------------------------------------------------------------- +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn convert_u32() { + let pascals: Pascals = 1_000.pascals(); + let kilo_pascals: KiloPascals = 1.kilo_pascals(); + + assert_eq!(pascals.0, kilo_pascals.to_pascals().0); + assert_eq!(kilo_pascals.0, pascals.to_kilo_pascals().0); + } +}