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§
Sourcefn test(&mut self, value: &T) -> bool
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§
Sourcefn into_box(self) -> BoxStatefulPredicate<T>where
Self: Sized + 'static,
fn into_box(self) -> BoxStatefulPredicate<T>where
Self: Sized + 'static,
Sourcefn into_rc(self) -> RcStatefulPredicate<T>where
Self: Sized + 'static,
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.
Sourcefn into_arc(self) -> ArcStatefulPredicate<T>
fn into_arc(self) -> ArcStatefulPredicate<T>
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.
Sourcefn to_box(&self) -> BoxStatefulPredicate<T>
fn to_box(&self) -> BoxStatefulPredicate<T>
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.
Sourcefn to_rc(&self) -> RcStatefulPredicate<T>
fn to_rc(&self) -> RcStatefulPredicate<T>
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.
Sourcefn to_arc(&self) -> ArcStatefulPredicate<T>
fn to_arc(&self) -> ArcStatefulPredicate<T>
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.
Sourcefn to_fn(&self) -> impl FnMut(&T) -> bool
fn to_fn(&self) -> impl FnMut(&T) -> bool
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§
impl<F, T> StatefulPredicate<T> for F
Implements StatefulPredicate<T> for FnMut(&T) -> bool closures.
This blanket implementation lets mutable closures be used directly
wherever a StatefulPredicate is expected.