diff options
Diffstat (limited to 'src/pressure/mod.rs')
| -rw-r--r-- | src/pressure/mod.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/pressure/mod.rs b/src/pressure/mod.rs new file mode 100644 index 0000000..9b91aa5 --- /dev/null +++ b/src/pressure/mod.rs @@ -0,0 +1,29 @@ +mod bar; +mod kilopascal; +mod psi; +mod unit; + +pub use bar::Bar; +pub use kilopascal::Kilopascal; +pub use psi::Psi; +pub use unit::Unit; + +pub fn convert<F: Into<f64>>(val: F, from: Unit, to: Unit) -> f64 { + match from { + Unit::Kilopascal => match to { + Unit::Kilopascal => val.into(), + Unit::Bar => Bar::from(Kilopascal(val.into())).0, + Unit::Psi => Psi::from(Kilopascal(val.into())).0, + }, + Unit::Bar => match to { + Unit::Bar => val.into(), + Unit::Kilopascal => Kilopascal::from(Bar(val.into())).0, + Unit::Psi => Psi::from(Bar(val.into())).0, + }, + Unit::Psi => match to { + Unit::Psi => val.into(), + Unit::Kilopascal => Kilopascal::from(Psi(val.into())).0, + Unit::Bar => Bar::from(Psi(val.into())).0, + }, + } +} |