[][src]Enum cfgmap::Condition

pub enum Condition {
    IsInt,
    IsFloat,
    IsStr,
    IsList,
    IsBool,
    IsMap,
    And(Box<Condition>, Box<Condition>),
    Or(Box<Condition>, Box<Condition>),
    Not(Box<Condition>),
    IsExactlyInt(i64),
    IsExactlyFloat(f64),
    IsExactlyStr(String),
    IsExactlyList(Vec<CfgValue>),
    IsExactlyMap(CfgMap),
    IsTrue,
    IsListWith(Box<Condition>),
    IsListWithLength(usize),
    IsNull,
    IsDatetime,
    TRUE,
    FALSE,
}

Different possible conditions.

Many conditions are self explanatory, such as IsInt and IsList. Complex conditions can be created easily using the | and & operators. So, for example, if you want to check whether an enum is an integer, or a float, you can do the following:

value.check_that(IsInt | IsFloat);

If you'd rather use methods, the following is equivalent:

value.check_that(IsInt.or(IsFloat));

Both of the above examples expand to the following:

value.check_that(Or(Box::new(IsInt), Box::new(IsFloat)));

If you'd like to not only check the type of a CfgValue, but also the value its wrapped in, you can use the Exactly conditions:

let value = Int(5);
assert!(value.check_that(IsExactlyInt(5)));

These exist for all CfgValues. There also exist other miscellaneous conditions, such as IsListWithLength(usize) or IsListWith(Box<Condition>), which serve other purposes.

Variants

IsInt
IsFloat
IsStr
IsList
IsBool
IsMap

A combination of two conditions.

If both evaluate to TRUE, the result is TRUE, otherwise it is FALSE.

A combination of two conditions.

If one evaluates to TRUE, the result is TRUE, otherwise it is FALSE.

Represents a negation.

IsExactlyInt(i64)

Does an exact comparison with an integer.

IsExactlyFloat(f64)

Does an exact comparison with an float.

IsExactlyStr(String)

Does an exact comparison with a string.

IsExactlyList(Vec<CfgValue>)

Does an exact comparison with a Vec<CfgValue>.

IsExactlyMap(CfgMap)

Does an exact comparison with a CfgMap

IsTrue

Verifies it to be a Bool, and checks whether it is true.

IsListWith(Box<Condition>)

Verifies it to be a List and applies the condition to each of its elements.

IsListWithLength(usize)

Verifies it to be a List, while also having a specific length.

IsNull

Verifies the value to be null. Only availiable while using from_json.

IsDatetime

Verifies the value to be a Datetime. Only available while using from_toml.

TRUE

A result condition. When executed this will always return true.

FALSE

A result condition. When executed this will always return false.

Methods

impl Condition[src]

pub fn and(self, other: Condition) -> Condition[src]

Helper function to generate an AND condition.

pub fn or(self, other: Condition) -> Condition[src]

Helper function to generate an OR condition.

pub fn not(self) -> Condition[src]

Helper function to generate a NOT condition.

pub fn execute(&self, input: &CfgValue) -> Condition[src]

Executes the condition. For all conditions, this function will return one of the result conditions - TRUE or FALSE. All conditions are executed on the input that is passed - including conditions within AND and OR combinations.

Examples

use cfgmap::{Condition::*, CfgValue::*};
assert!(IsInt.execute(&Int(5)).to_bool()); 
assert!(!IsInt.execute(&Float(1.0)).to_bool());
assert!((IsInt | IsFloat).execute(&Float(1.0)).to_bool());

pub fn to_bool(&self) -> bool[src]

Converts from result condition to boolean.

All non-TRUE values are interpreted as FALSE. Reasoning behind this is that all other values are either incomplete conditions, or FALSE.

Trait Implementations

impl BitAnd<Condition> for Condition[src]

Syntactical sugar for a.and(b).

type Output = Self

The resulting type after applying the & operator.

impl BitOr<Condition> for Condition[src]

Syntactical sugar for a.or(b).

type Output = Self

The resulting type after applying the | operator.

impl Clone for Condition[src]

impl From<Condition> for bool[src]

impl From<bool> for Condition[src]

impl Not for Condition[src]

Syntactical sugar for a.not()

type Output = Self

The resulting type after applying the ! operator.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,