pub trait FnMutStatefulMutatorOps<T>: FnMut(&mut T) + Sized {
// Provided method
fn and_then<C>(self, next: C) -> BoxStatefulMutator<T>
where Self: 'static,
C: StatefulMutator<T> + 'static,
T: 'static { ... }
}Expand description
Extension trait providing mutator composition methods for closures
Provides and_then and other composition methods for all closures that
implement FnMut(&mut T), enabling direct method chaining on closures
without explicit wrapper types.
§Features
- Natural Syntax: Chain operations directly on closures
- Returns BoxMutator: Composition results are
BoxMutator<T>for continued chaining - Zero Cost: No overhead when composing closures
- Automatic Implementation: All
FnMut(&mut T)closures get these methods automatically
§Examples
use prism3_function::{Mutator, FnMutatorOps};
let chained = (|x: &mut i32| *x *= 2)
.and_then(|x: &mut i32| *x += 10);
let mut value = 5;
let mut result = chained;
result.mutate(&mut value);
assert_eq!(value, 20); // (5 * 2) + 10§Author
Haixing Hu
Provided Methods§
Sourcefn and_then<C>(self, next: C) -> BoxStatefulMutator<T>where
Self: 'static,
C: StatefulMutator<T> + 'static,
T: 'static,
fn and_then<C>(self, next: C) -> BoxStatefulMutator<T>where
Self: 'static,
C: StatefulMutator<T> + 'static,
T: 'static,
Chains another mutator in sequence
Returns a new mutator that first executes the current operation, then
executes the next operation. Consumes the current closure and returns
BoxMutator<T>.
§Parameters
next- The mutator to execute after the current operation. Note: This parameter is passed by value and will transfer ownership. If you need to preserve the original mutator, clone it first (if it implementsClone). Can be:- A closure:
|x: &mut T| - A
BoxMutator<T> - An
ArcMutator<T> - An
RcMutator<T> - Any type implementing
Mutator<T>
- A closure:
§Returns
Returns the composed BoxMutator<T>
§Examples
use prism3_function::{Mutator, FnMutatorOps};
let chained = (|x: &mut i32| *x *= 2)
.and_then(|x: &mut i32| *x += 10)
.and_then(|x: &mut i32| println!("Result: {}", x));
let mut value = 5;
let mut result = chained;
result.mutate(&mut value); // Prints: Result: 20
assert_eq!(value, 20);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§
impl<T, F> FnMutStatefulMutatorOps<T> for F
Implements FnMutatorOps for all closure types