Skip to main content

StatefulBiPredicate

Trait StatefulBiPredicate 

Source
pub trait StatefulBiPredicate<T, U> {
    // Required method
    fn test(&mut self, first: &T, second: &U) -> bool;

    // Provided methods
    fn into_box(self) -> BoxStatefulBiPredicate<T, U>
       where Self: Sized + 'static { ... }
    fn into_rc(self) -> RcStatefulBiPredicate<T, U>
       where Self: Sized + 'static { ... }
    fn into_arc(self) -> ArcStatefulBiPredicate<T, U>
       where Self: Sized + Send + 'static { ... }
    fn into_fn(self) -> impl FnMut(&T, &U) -> bool
       where Self: Sized + 'static { ... }
    fn to_box(&self) -> BoxStatefulBiPredicate<T, U>
       where Self: Clone + Sized + 'static { ... }
    fn to_rc(&self) -> RcStatefulBiPredicate<T, U>
       where Self: Clone + Sized + 'static { ... }
    fn to_arc(&self) -> ArcStatefulBiPredicate<T, U>
       where Self: Clone + Sized + Send + 'static { ... }
    fn to_fn(&self) -> impl FnMut(&T, &U) -> bool
       where Self: Clone + Sized + 'static { ... }
}
Expand description

A stateful bi-predicate trait for testing pairs with mutable internal state.

This trait represents closures and wrapper types equivalent to FnMut(&T, &U) -> bool: each call borrows the predicate mutably so the predicate can update counters, caches, rolling state, or other internal data while leaving both tested values borrowed immutably.

§Type Parameters

  • T - The type of the first value being tested.
  • U - The type of the second value being tested.

Required Methods§

Source

fn test(&mut self, first: &T, second: &U) -> bool

Tests whether the given values satisfy this bi-predicate.

The method takes &mut self because evaluating the predicate may update internal state. The tested values themselves are only borrowed immutably and are not modified by this API.

§Parameters
  • first - The first value to test.
  • second - The second value to test.
§Returns

true if the values satisfy this bi-predicate, false otherwise.

Provided Methods§

Source

fn into_box(self) -> BoxStatefulBiPredicate<T, U>
where Self: Sized + 'static,

Converts this bi-predicate into a BoxStatefulBiPredicate.

This consumes self and wraps it in a single-owner stateful bi-predicate. The returned wrapper forwards each call to this predicate’s test method.

§Returns

A BoxStatefulBiPredicate wrapping this predicate.

Source

fn into_rc(self) -> RcStatefulBiPredicate<T, U>
where Self: Sized + 'static,

Converts this bi-predicate into an RcStatefulBiPredicate.

This consumes self and wraps it in a single-threaded shared stateful bi-predicate using Rc<RefCell<_>>.

§Returns

An RcStatefulBiPredicate wrapping this predicate.

Source

fn into_arc(self) -> ArcStatefulBiPredicate<T, U>
where Self: Sized + Send + 'static,

Converts this bi-predicate into an ArcStatefulBiPredicate.

This consumes self and wraps it in a thread-safe shared stateful bi-predicate using Arc<Mutex<_>>. The wrapped predicate must be Send so it can be stored behind the thread-safe wrapper.

§Returns

An ArcStatefulBiPredicate wrapping this predicate.

Source

fn into_fn(self) -> impl FnMut(&T, &U) -> bool
where Self: Sized + 'static,

Converts this bi-predicate into a closure implementing FnMut(&T, &U) -> bool.

This consumes self and returns a mutable closure that forwards each call to test.

§Returns

A closure implementing FnMut(&T, &U) -> bool.

Source

fn to_box(&self) -> BoxStatefulBiPredicate<T, U>
where Self: Clone + Sized + 'static,

Converts a clone of this bi-predicate into a BoxStatefulBiPredicate.

The original predicate remains available after this call. The cloned predicate owns independent state unless its clone implementation shares state internally.

§Returns

A BoxStatefulBiPredicate wrapping a clone of this predicate.

Source

fn to_rc(&self) -> RcStatefulBiPredicate<T, U>
where Self: Clone + Sized + 'static,

Converts a clone of this bi-predicate into an RcStatefulBiPredicate.

The original predicate remains available after this call. The cloned predicate owns independent state unless its clone implementation shares state internally.

§Returns

An RcStatefulBiPredicate wrapping a clone of this predicate.

Source

fn to_arc(&self) -> ArcStatefulBiPredicate<T, U>
where Self: Clone + Sized + Send + 'static,

Converts a clone of this bi-predicate into an ArcStatefulBiPredicate.

The original predicate remains available after this call. The cloned predicate must be Send so it can be stored behind the thread-safe wrapper.

§Returns

An ArcStatefulBiPredicate wrapping a clone of this predicate.

Source

fn to_fn(&self) -> impl FnMut(&T, &U) -> bool
where Self: Clone + Sized + 'static,

Converts a clone of this bi-predicate into a mutable closure.

The original predicate remains available after this call. The cloned predicate owns independent state unless its clone implementation shares state internally.

§Returns

A closure implementing FnMut(&T, &U) -> bool.

Implementors§

Source§

impl<T, U> StatefulBiPredicate<T, U> for ArcStatefulBiPredicate<T, U>

Source§

impl<T, U> StatefulBiPredicate<T, U> for BoxStatefulBiPredicate<T, U>

Source§

impl<T, U> StatefulBiPredicate<T, U> for RcStatefulBiPredicate<T, U>

Source§

impl<T, U, F> StatefulBiPredicate<T, U> for F
where F: FnMut(&T, &U) -> bool,