pub trait FnBiPredicateOps<T, U>:
Fn(&T, &U) -> bool
+ Sized
+ 'static {
// Provided methods
fn and<P>(self, other: P) -> BoxBiPredicate<T, U>
where P: BiPredicate<T, U> + 'static,
T: 'static,
U: 'static { ... }
fn or<P>(self, other: P) -> BoxBiPredicate<T, U>
where P: BiPredicate<T, U> + 'static,
T: 'static,
U: 'static { ... }
fn not(self) -> BoxBiPredicate<T, U>
where T: 'static,
U: 'static { ... }
fn nand<P>(self, other: P) -> BoxBiPredicate<T, U>
where P: BiPredicate<T, U> + 'static,
T: 'static,
U: 'static { ... }
fn xor<P>(self, other: P) -> BoxBiPredicate<T, U>
where P: BiPredicate<T, U> + 'static,
T: 'static,
U: 'static { ... }
fn nor<P>(self, other: P) -> BoxBiPredicate<T, U>
where P: BiPredicate<T, U> + 'static,
T: 'static,
U: 'static { ... }
}Expand description
Extension trait providing logical composition methods for closures.
This trait is automatically implemented for all closures and
function pointers that match Fn(&T, &U) -> bool, enabling method
chaining starting from a closure.
§Examples
use prism3_function::bi_predicate::{BiPredicate, FnBiPredicateOps};
let is_sum_positive = |x: &i32, y: &i32| x + y > 0;
let first_larger = |x: &i32, y: &i32| x > y;
// Combine bi-predicates using extension methods
let pred = is_sum_positive.and(first_larger);
assert!(pred.test(&10, &5));
assert!(!pred.test(&3, &8));§Author
Haixing Hu
Provided Methods§
Sourcefn and<P>(self, other: P) -> BoxBiPredicate<T, U>where
P: BiPredicate<T, U> + 'static,
T: 'static,
U: 'static,
fn and<P>(self, other: P) -> BoxBiPredicate<T, U>where
P: BiPredicate<T, U> + 'static,
T: 'static,
U: 'static,
Returns a bi-predicate that represents the logical AND of this bi-predicate and another.
§Parameters
other- The other bi-predicate to combine with. Note: This parameter is passed by value and will transfer ownership. If you need to preserve the original bi-predicate, clone it first (if it implementsClone). Can be:- Another closure:
|x: &T, y: &U| -> bool - A function pointer:
fn(&T, &U) -> bool - A
BoxBiPredicate<T, U> - An
RcBiPredicate<T, U> - An
ArcBiPredicate<T, U> - Any type implementing
BiPredicate<T, U>
- Another closure:
§Returns
A BoxBiPredicate representing the logical AND.
Sourcefn or<P>(self, other: P) -> BoxBiPredicate<T, U>where
P: BiPredicate<T, U> + 'static,
T: 'static,
U: 'static,
fn or<P>(self, other: P) -> BoxBiPredicate<T, U>where
P: BiPredicate<T, U> + 'static,
T: 'static,
U: 'static,
Returns a bi-predicate that represents the logical OR of this bi-predicate and another.
§Parameters
other- The other bi-predicate to combine with. Note: This parameter is passed by value and will transfer ownership. If you need to preserve the original bi-predicate, clone it first (if it implementsClone). Can be:- Another closure:
|x: &T, y: &U| -> bool - A function pointer:
fn(&T, &U) -> bool - A
BoxBiPredicate<T, U> - An
RcBiPredicate<T, U> - An
ArcBiPredicate<T, U> - Any type implementing
BiPredicate<T, U>
- Another closure:
§Returns
A BoxBiPredicate representing the logical OR.
Sourcefn not(self) -> BoxBiPredicate<T, U>where
T: 'static,
U: 'static,
fn not(self) -> BoxBiPredicate<T, U>where
T: 'static,
U: 'static,
Returns a bi-predicate that represents the logical negation of this bi-predicate.
§Returns
A BoxBiPredicate representing the logical negation.
Sourcefn nand<P>(self, other: P) -> BoxBiPredicate<T, U>where
P: BiPredicate<T, U> + 'static,
T: 'static,
U: 'static,
fn nand<P>(self, other: P) -> BoxBiPredicate<T, U>where
P: BiPredicate<T, U> + 'static,
T: 'static,
U: 'static,
Returns a bi-predicate that represents the logical NAND (NOT AND) of this bi-predicate and another.
NAND returns true unless both bi-predicates are true.
Equivalent to !(self AND other).
§Parameters
other- The other bi-predicate to combine with. Note: This parameter is passed by value and will transfer ownership. If you need to preserve the original bi-predicate, clone it first (if it implementsClone). Can be:- Another closure:
|x: &T, y: &U| -> bool - A function pointer:
fn(&T, &U) -> bool - A
BoxBiPredicate<T, U> - An
RcBiPredicate<T, U> - An
ArcBiPredicate<T, U> - Any type implementing
BiPredicate<T, U>
- Another closure:
§Returns
A BoxBiPredicate representing the logical NAND.
Sourcefn xor<P>(self, other: P) -> BoxBiPredicate<T, U>where
P: BiPredicate<T, U> + 'static,
T: 'static,
U: 'static,
fn xor<P>(self, other: P) -> BoxBiPredicate<T, U>where
P: BiPredicate<T, U> + 'static,
T: 'static,
U: 'static,
Returns a bi-predicate that represents the logical XOR (exclusive OR) of this bi-predicate and another.
XOR returns true if exactly one of the bi-predicates is
true.
§Parameters
other- The other bi-predicate to combine with. Note: This parameter is passed by value and will transfer ownership. If you need to preserve the original bi-predicate, clone it first (if it implementsClone). Can be:- Another closure:
|x: &T, y: &U| -> bool - A function pointer:
fn(&T, &U) -> bool - A
BoxBiPredicate<T, U> - An
RcBiPredicate<T, U> - An
ArcBiPredicate<T, U> - Any type implementing
BiPredicate<T, U>
- Another closure:
§Returns
A BoxBiPredicate representing the logical XOR.
Sourcefn nor<P>(self, other: P) -> BoxBiPredicate<T, U>where
P: BiPredicate<T, U> + 'static,
T: 'static,
U: 'static,
fn nor<P>(self, other: P) -> BoxBiPredicate<T, U>where
P: BiPredicate<T, U> + 'static,
T: 'static,
U: 'static,
Returns a bi-predicate that represents the logical NOR (NOT OR) of this bi-predicate and another.
NOR returns true only if both bi-predicates are false.
Equivalent to !(self OR other).
§Parameters
other- The other bi-predicate to combine with. Note: This parameter is passed by value and will transfer ownership. If you need to preserve the original bi-predicate, clone it first (if it implementsClone). Can be:- Another closure:
|x: &T, y: &U| -> bool - A function pointer:
fn(&T, &U) -> bool - A
BoxBiPredicate<T, U> - An
RcBiPredicate<T, U> - An
ArcBiPredicate<T, U> - Any type implementing
BiPredicate<T, U>
- Another closure:
§Returns
A BoxBiPredicate representing the logical NOR.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.