Trait predicates::prelude::Predicate
[−]
[src]
pub trait Predicate<Item: ?Sized> { fn eval(&self, variable: &Item) -> bool; fn and<B>(self, other: B) -> AndPredicate<Self, B, Item>
where
B: Predicate<Item>,
Self: Sized, { ... } fn or<B>(self, other: B) -> OrPredicate<Self, B, Item>
where
B: Predicate<Item>,
Self: Sized, { ... } fn not(self) -> NotPredicate<Self, Item>
where
Self: Sized, { ... } fn boxed(self) -> BoxPredicate<Item>
where
Self: Sized + Send + Sync + 'static, { ... } }
Trait for generically evaluating a type against a dynamically created predicate function.
The exact meaning of eval
depends on the situation, but will usually
mean that the evaluated item is in some sort of pre-defined set. This is
different from Ord
and Eq
in that an item
will almost never be the
same type as the implementing Predicate
type.
Required Methods
fn eval(&self, variable: &Item) -> bool
Execute this Predicate
against variable
, returning the resulting
boolean.
Provided Methods
fn and<B>(self, other: B) -> AndPredicate<Self, B, Item> where
B: Predicate<Item>,
Self: Sized,
B: Predicate<Item>,
Self: Sized,
Compute the logical AND of two Predicate
results, returning the result.
Examples
use predicates::prelude::*; let predicate_fn1 = predicate::always().and(predicate::always()); let predicate_fn2 = predicate::always().and(predicate::never()); assert_eq!(true, predicate_fn1.eval(&4)); assert_eq!(false, predicate_fn2.eval(&4));
fn or<B>(self, other: B) -> OrPredicate<Self, B, Item> where
B: Predicate<Item>,
Self: Sized,
B: Predicate<Item>,
Self: Sized,
Compute the logical OR of two Predicate
results, returning the result.
Examples
use predicates::prelude::*; let predicate_fn1 = predicate::always().or(predicate::always()); let predicate_fn2 = predicate::always().or(predicate::never()); let predicate_fn3 = predicate::never().or(predicate::never()); assert_eq!(true, predicate_fn1.eval(&4)); assert_eq!(true, predicate_fn2.eval(&4)); assert_eq!(false, predicate_fn3.eval(&4));
fn not(self) -> NotPredicate<Self, Item> where
Self: Sized,
Self: Sized,
Compute the logical NOT of a Predicate
, returning the result.
Examples
use predicates::prelude::*; let predicate_fn1 = predicate::always().not(); let predicate_fn2 = predicate::never().not(); assert_eq!(false, predicate_fn1.eval(&4)); assert_eq!(true, predicate_fn2.eval(&4));
fn boxed(self) -> BoxPredicate<Item> where
Self: Sized + Send + Sync + 'static,
Self: Sized + Send + Sync + 'static,
Returns a BoxPredicate
wrapper around this Predicate
type.
Returns a BoxPredicate
wrapper around this Predicate type. The
BoxPredicate` type has a number of useful properties:
- It stores the inner predicate as a trait object, so the type of
BoxPredicate
will always be the same even if steps are added or removed from the predicate. - It is a common type, allowing it to be stored in vectors or other collection types.
- It implements
Debug
andDisplay
.
Examples
use predicates::prelude::*; let predicates = vec![ predicate::always().boxed(), predicate::never().boxed(), ]; assert_eq!(true, predicates[0].eval(&4)); assert_eq!(false, predicates[1].eval(&4));
Implementors
impl<Item> Predicate<Item> for BoxPredicate<Item> where
Item: ?Sized,impl<Item> Predicate<Item> for BooleanPredicate<Item>
impl<F, T> Predicate<T> for FnPredicate<F, T> where
F: Fn(&T) -> bool,impl<T> Predicate<T> for EqPredicate<T> where
T: PartialEq,impl<T> Predicate<T> for OrdPredicate<T> where
T: PartialOrd,impl<T> Predicate<T> for InPredicate<T> where
T: PartialEq,impl<T> Predicate<T> for OrdInPredicate<T> where
T: Ord,impl<T> Predicate<T> for HashableInPredicate<T> where
T: Hash + Eq,impl<M1, M2, Item> Predicate<Item> for AndPredicate<M1, M2, Item> where
M1: Predicate<Item>,
M2: Predicate<Item>,
Item: ?Sized,impl<M1, M2, Item> Predicate<Item> for OrPredicate<M1, M2, Item> where
M1: Predicate<Item>,
M2: Predicate<Item>,
Item: ?Sized,impl<M, Item> Predicate<Item> for NotPredicate<M, Item> where
M: Predicate<Item>,
Item: ?Sized,impl Predicate<str> for IsEmptyPredicate
impl Predicate<str> for StartsWithPredicate
impl Predicate<str> for EndsWithPredicate
impl Predicate<str> for ContainsPredicate
impl Predicate<str> for MatchesPredicate
impl Predicate<str> for DifferencePredicate
impl Predicate<str> for RegexPredicate
impl Predicate<Path> for ExistencePredicate
impl Predicate<Path> for FileTypePredicate
impl Predicate<f64> for IsClosePredicate