pub fn function<F, T>(function: F) -> FnPredicate<F, T>
Expand description
Creates a new predicate that wraps over the given function. The returned
type implements Predicate
and therefore has all combinators available to
it.
§Examples
use predicates::prelude::*;
struct Example {
string: String,
number: i32,
}
let string_check = predicate::function(|x: &Example| x.string == "hello");
let number_check = predicate::function(|x: &Example| x.number == 42);
let predicate_fn = string_check.and(number_check);
let good_example = Example { string: "hello".into(), number: 42 };
assert_eq!(true, predicate_fn.eval(&good_example));
let bad_example = Example { string: "goodbye".into(), number: 0 };
assert_eq!(false, predicate_fn.eval(&bad_example));