FnBiPredicateOps

Trait FnBiPredicateOps 

Source
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§

Source

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 implements Clone). 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>
§Returns

A BoxBiPredicate representing the logical AND.

Source

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 implements Clone). 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>
§Returns

A BoxBiPredicate representing the logical OR.

Source

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.

Source

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 implements Clone). 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>
§Returns

A BoxBiPredicate representing the logical NAND.

Source

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 implements Clone). 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>
§Returns

A BoxBiPredicate representing the logical XOR.

Source

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 implements Clone). 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>
§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.

Implementors§

Source§

impl<T, U, F> FnBiPredicateOps<T, U> for F
where F: Fn(&T, &U) -> bool + 'static,