Skip to main content

StatefulPredicate

Trait StatefulPredicate 

Source
pub trait StatefulPredicate<T> {
    // Required method
    fn test(&mut self, value: &T) -> bool;

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

A stateful predicate trait for testing values with mutable internal state.

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

§Type Parameters

  • T - The type of the value being tested.

Required Methods§

Source

fn test(&mut self, value: &T) -> bool

Tests whether the given value satisfies this predicate.

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

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

true if the value satisfies this predicate, false otherwise.

Provided Methods§

Source

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

Converts this predicate into a BoxStatefulPredicate.

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

§Returns

A BoxStatefulPredicate wrapping this predicate.

Source

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

Converts this predicate into an RcStatefulPredicate.

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

§Returns

An RcStatefulPredicate wrapping this predicate.

Source

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

Converts this predicate into an ArcStatefulPredicate.

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

§Returns

An ArcStatefulPredicate wrapping this predicate.

Source

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

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

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

§Returns

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

Source

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

Converts a clone of this predicate into a BoxStatefulPredicate.

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

§Returns

A BoxStatefulPredicate wrapping a clone of this predicate.

Source

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

Converts a clone of this predicate into an RcStatefulPredicate.

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

§Returns

An RcStatefulPredicate wrapping a clone of this predicate.

Source

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

Converts a clone of this predicate into an ArcStatefulPredicate.

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 ArcStatefulPredicate wrapping a clone of this predicate.

Source

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

Converts a clone of this 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) -> bool.

Implementors§

Source§

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

Implements StatefulPredicate<T> for FnMut(&T) -> bool closures.

This blanket implementation lets mutable closures be used directly wherever a StatefulPredicate is expected.

Source§

impl<T> StatefulPredicate<T> for ArcStatefulPredicate<T>

Source§

impl<T> StatefulPredicate<T> for BoxStatefulPredicate<T>

Source§

impl<T> StatefulPredicate<T> for RcStatefulPredicate<T>