Enum foxbox_taxonomy::values::Temperature
[−]
[src]
pub enum Temperature { F(f64), C(f64), }
A temperature. Internal representation may be either Fahrenheit or Celcius. The FoxBox adapters are expected to perform conversions to the format requested by their devices.
JSON
Values of this type are represented by objects {F; float}
or {C: float}
Variants
F | Fahrenheit JSONuse foxbox_taxonomy::values::*; use foxbox_taxonomy::parse::*; use foxbox_taxonomy::serialize::*; let source = "{ \"F\": 100 }"; let parsed = Temperature::from_str(source).unwrap(); if let Temperature::F(100.) = parsed { // As expected } else { panic!() } let serialized : JSON = parsed.to_json(&mut MultiPart::new()); let val = serialized.find("F").unwrap().as_f64().unwrap(); assert_eq!(val, 100.) | |
C | Celcius JSONuse foxbox_taxonomy::values::*; use foxbox_taxonomy::parse::*; use foxbox_taxonomy::serialize::*; let source = "{ \"C\": 100 }"; let parsed = Temperature::from_str(source).unwrap(); if let Temperature::C(100.) = parsed { // As expected } else { panic!() } let serialized : JSON = parsed.to_json(&mut MultiPart::new()); let val = serialized.find("C").unwrap().as_f64().unwrap(); assert_eq!(val, 100.) |
Methods
impl Temperature
fn as_f(&self) -> f64
Get a temperature in Fahrenheit.
fn as_c(&self) -> f64
Get a temperature in Celcius.