pub fn convert(value: f32, from: &str, to: &str) -> Option<f32>Expand description
Converts a reading between two units of the same quantity.
§Arguments
value- the reading.from- the unit it is in, such ascelsius.to- the unit wanted, such asfahrenheit.
§Returns
The reading in to, or None when the runner does not convert between the two. A unit
converts to itself, and temperature (celsius, fahrenheit, kelvin), pressure
(pascal, hectopascal, millibar, kilopascal, bar), and electrical units
(volt and millivolt) convert among their own kind.
§Examples
use pamoja_profile::wiring::convert;
assert_eq!(convert(100.0, "celsius", "fahrenheit"), Some(212.0));
assert_eq!(convert(1013.25, "hectopascal", "kilopascal"), Some(101.325));
assert_eq!(convert(20.0, "celsius", "percent"), None);