[−][src]Enum cfgmap::Condition
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 CfgValue
s. There also exist other miscellaneous conditions, such as
IsListWithLength(usize)
or IsListWith(Box<Condition>)
, which serve other purposes.
Variants
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.
Does an exact comparison with a Vec<CfgValue>
.
IsExactlyMap(CfgMap)
Does an exact comparison with a CfgMap
Verifies it to be a Bool
, and checks whether it is true.
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.
Verifies the value to be null
. Only availiable while using from_json
.
Verifies the value to be a Datetime
. Only available while using from_toml
.
A result condition. When executed this will always return true
.
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.
fn bitand(self, rhs: Self) -> Self::Output
[src]
impl BitOr<Condition> for Condition
[src]
Syntactical sugar for a.or(b)
.
type Output = Self
The resulting type after applying the |
operator.
fn bitor(self, rhs: Self) -> Self::Output
[src]
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()
Auto Trait Implementations
impl RefUnwindSafe for Condition
impl Send for Condition
impl Sync for Condition
impl Unpin for Condition
impl UnwindSafe for Condition
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,