diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2023-02-05 13:35:23 -0330 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2023-02-05 13:35:23 -0330 |
| commit | a07f4ff774dd0ba0da3a502909d078ccf3e0c63f (patch) | |
| tree | 47b76316dc08bf266680ff7893f7a430bc90a1c4 /src/pressure/mod.rs | |
| parent | 3a1e9d081cc299a0ce3e950282464986a36376d9 (diff) | |
| download | volute-rust.zip | |
pressurerust
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, + }, + } +} |