Enum foxbox_taxonomy::values::Range [] [src]

pub enum Range {
    Leq(Value),
    Geq(Value),
    BetweenEq {
        min: Value,
        max: Value,
    },
    OutOfStrict {
        min: Value,
        max: Value,
    },
    Eq(Value),
}

A comparison between two values.

JSON

A range is an object with one field {key: value}.

Variants

Leq

Leq(x) accepts any value v such that v <= x.

JSON

extern crate foxbox_taxonomy;
extern crate serde_json;

use foxbox_taxonomy::values::*;
use foxbox_taxonomy::parse::*;
use foxbox_taxonomy::serialize::*;


let source = "{
  \"Leq\": { \"OnOff\": \"On\" }
}";

let parsed = Range::from_str(source).unwrap();
if let Range::Leq(ref leq) = parsed {
  assert_eq!(*leq, Value::OnOff(OnOff::On));
} else {
  panic!();
}

let as_json = parsed.to_json(&mut MultiPart::new());
let as_string = serde_json::to_string(&as_json).unwrap();
assert_eq!(as_string, "{\"Leq\":{\"OnOff\":\"On\"}}");
Geq

Geq(x) accepts any value v such that v >= x.

BetweenEq

BetweenEq {min, max} accepts any value v such that min <= v and v <= max. If max < min, it never accepts anything.

Fields

min
max
OutOfStrict

OutOfStrict {min, max} accepts any value v such that v < min or max < v

Fields

min
max
Eq

Eq(x) accespts any value v such that v == x

Methods

impl Range

fn contains(&self, value: &Value) -> bool

Determine if a value is accepted by this range.

fn get_type(&self) -> Result<Type, TypeError>

Get the type associated to this range.

If this range has a min and a max with conflicting types, produce an error.

Trait Implementations

impl Serialize for Range

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

impl Deserialize for Range

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

impl Parser<Range> for Range

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 Range

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

Derived Implementations

impl PartialEq for Range

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

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

impl Debug for Range

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

impl Clone for Range

fn clone(&self) -> Range

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