pub trait FnConsumerOps<T>: Fn(&T) + Sized {
// Provided method
fn and_then<C>(self, next: C) -> BoxConsumer<T>
where Self: 'static,
C: Consumer<T> + 'static,
T: 'static { ... }
}Expand description
Extension trait providing readonly consumer composition methods for closures
Provides and_then and other composition methods for all closures
implementing Fn(&T), allowing closures to directly chain methods without
explicit wrapper types.
§Features
- Natural Syntax: Chain operations directly on closures
- Returns BoxConsumer: Combined results can continue chaining
- Zero Cost: No overhead when composing closures
- Auto-implementation: All
Fn(&T)closures automatically get these methods
§Examples
use prism3_function::{Consumer, FnConsumerOps};
let chained = (|x: &i32| {
println!("First: {}", x);
}).and_then(|x: &i32| {
println!("Second: {}", x);
});
chained.accept(&5);§Author
Haixing Hu
Provided Methods§
Sourcefn and_then<C>(self, next: C) -> BoxConsumer<T>where
Self: 'static,
C: Consumer<T> + 'static,
T: 'static,
fn and_then<C>(self, next: C) -> BoxConsumer<T>where
Self: 'static,
C: Consumer<T> + 'static,
T: 'static,
Sequentially chain another readonly consumer
Returns a new consumer that executes the current operation first, then the
next operation. Consumes the current closure and returns
BoxConsumer<T>.
§Type Parameters
C- Type of the next consumer
§Parameters
next- Consumer to execute after the current operation
§Returns
Returns a combined BoxConsumer<T>
§Examples
use prism3_function::{Consumer, FnConsumerOps};
let chained = (|x: &i32| {
println!("First: {}", x);
}).and_then(|x: &i32| {
println!("Second: {}", x);
}).and_then(|x: &i32| println!("Third: {}", x));
chained.accept(&5);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> FnConsumerOps<T> for F
Implement FnConsumerOps for all closure types