predicates::iter

Function in_hash

Source
pub fn in_hash<I, T>(iter: I) -> HashableInPredicate<T>
where T: Hash + Eq + Debug, I: IntoIterator<Item = T>,
Expand description

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 Hash + Eq. 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_hash(vec![1, 3, 5]);
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_hash(vec!["a", "c", "e"]);
assert_eq!(true, predicate_fn.eval("a"));
assert_eq!(false, predicate_fn.eval("b"));
assert_eq!(true, predicate_fn.eval("c"));