Struct predicates::iter::InPredicate
source · Expand description
Predicate that returns true if variable is a member of the pre-defined
set, otherwise returns false.
Note that this implementation places the fewest restrictions on the
underlying Item type at the expense of having the least performant
implementation (linear search). If the type to be searched is Hash + Eq,
it is much more efficient to use HashableInPredicate and
in_hash. The implementation-specific predicates will be
deprecated when Rust supports trait specialization.
Implementations§
source§impl<T> InPredicate<T>where
T: Ord + Debug,
impl<T> InPredicate<T>where
T: Ord + Debug,
sourcepub fn sort(self) -> OrdInPredicate<T>
pub fn sort(self) -> OrdInPredicate<T>
Creates a new predicate that will return true when the given variable is
contained with the set of items provided.
Note that this implementation requires Item to be Ord. The
InPredicate uses a less efficient search algorithm but only
requires Item implement PartialEq. The implementation-specific
predicates will be deprecated when Rust supports trait specialization.
Examples
use predicates::prelude::*;
let predicate_fn = predicate::in_iter(vec![1, 3, 5]).sort();
assert_eq!(true, predicate_fn.eval(&1));
assert_eq!(false, predicate_fn.eval(&2));
assert_eq!(true, predicate_fn.eval(&3));
let predicate_fn = predicate::in_iter(vec!["a", "c", "e"]).sort();
assert_eq!(true, predicate_fn.eval("a"));
assert_eq!(false, predicate_fn.eval("b"));
assert_eq!(true, predicate_fn.eval("c"));
let predicate_fn = predicate::in_iter(vec![String::from("a"), String::from("c"), String::from("e")]).sort();
assert_eq!(true, predicate_fn.eval("a"));
assert_eq!(false, predicate_fn.eval("b"));
assert_eq!(true, predicate_fn.eval("c"));Trait Implementations§
source§impl<T> Clone for InPredicate<T>where
T: PartialEq + Debug + Clone,
impl<T> Clone for InPredicate<T>where
T: PartialEq + Debug + Clone,
source§fn clone(&self) -> InPredicate<T>
fn clone(&self) -> InPredicate<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl<T> PartialEq<InPredicate<T>> for InPredicate<T>where
T: PartialEq + Debug + PartialEq,
impl<T> PartialEq<InPredicate<T>> for InPredicate<T>where
T: PartialEq + Debug + PartialEq,
source§fn eq(&self, other: &InPredicate<T>) -> bool
fn eq(&self, other: &InPredicate<T>) -> bool
self and other values to be equal, and is used
by ==.source§impl<P, T> Predicate<P> for InPredicate<T>where
T: Borrow<P> + PartialEq + Debug,
P: PartialEq + Debug + ?Sized,
impl<P, T> Predicate<P> for InPredicate<T>where
T: Borrow<P> + PartialEq + Debug,
P: PartialEq + Debug + ?Sized,
source§impl<T> PredicateReflection for InPredicate<T>where
T: PartialEq + Debug,
impl<T> PredicateReflection for InPredicate<T>where
T: PartialEq + Debug,
impl<T> Eq for InPredicate<T>where
T: PartialEq + Debug + Eq,
impl<T> StructuralEq for InPredicate<T>where
T: PartialEq + Debug,
impl<T> StructuralPartialEq for InPredicate<T>where
T: PartialEq + Debug,
Auto Trait Implementations§
impl<T> RefUnwindSafe for InPredicate<T>where
T: RefUnwindSafe,
impl<T> Send for InPredicate<T>where
T: Send,
impl<T> Sync for InPredicate<T>where
T: Sync,
impl<T> Unpin for InPredicate<T>where
T: Unpin,
impl<T> UnwindSafe for InPredicate<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<P, Item> PredicateBooleanExt<Item> for Pwhere
P: Predicate<Item>,
Item: ?Sized,
impl<P, Item> PredicateBooleanExt<Item> for Pwhere
P: Predicate<Item>,
Item: ?Sized,
source§fn and<B>(self, other: B) -> AndPredicate<Self, B, Item>where
B: Predicate<Item>,
Self: Sized,
fn and<B>(self, other: B) -> AndPredicate<Self, B, Item>where
B: Predicate<Item>,
Self: Sized,
Predicate results, returning the result. Read more