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

JSON

use 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

JSON

use 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.

Trait Implementations

impl Deserialize for Temperature

fn deserialize<__D>(deserializer: &mut __D) -> Result<Temperature, __D::Error> where __D: Deserializer

impl Serialize for Temperature

fn serialize<__S>(&self, serializer: &mut __S) -> Result<(), __S::Error> where __S: Serializer

impl Parser<Temperature> for Temperature

fn description() -> String

fn parse(path: Path, source: &mut JSON) -> Result<Self, ParseError>

fn from_str(source: &str) -> Result<T, ParseError>

fn take(path: Path, source: &mut JSON, field_name: &str) -> Result<T, ParseError>

fn take_opt(path: Path, source: &mut JSON, field_name: &str) -> Option<Result<T, ParseError>>

fn take_vec_opt(path: Path, source: &mut JSON, field_name: &str) -> Option<Result<Vec<T>, ParseError>>

fn take_vec(path: Path, source: &mut JSON, field_name: &str) -> Result<Vec<T>, ParseError>

impl ToJSON for Temperature

fn to_json(&self, parts: &mut BinaryParts) -> JSON

impl PartialOrd for Temperature

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

1.0.0fn lt(&self, other: &Rhs) -> bool

1.0.0fn le(&self, other: &Rhs) -> bool

1.0.0fn gt(&self, other: &Rhs) -> bool

1.0.0fn ge(&self, other: &Rhs) -> bool

Derived Implementations

impl PartialEq for Temperature

fn eq(&self, __arg_0: &Temperature) -> bool

fn ne(&self, __arg_0: &Temperature) -> bool

impl Clone for Temperature

fn clone(&self) -> Temperature

1.0.0fn clone_from(&mut self, source: &Self)

impl Debug for Temperature

fn fmt(&self, __arg_0: &mut Formatter) -> Result