pub trait FnReadonlyBiConsumerOps<T, U>: Fn(&T, &U) + Sized {
// Provided method
fn and_then<C>(self, next: C) -> BoxReadonlyBiConsumer<T, U>
where Self: 'static,
C: ReadonlyBiConsumer<T, U> + 'static,
T: 'static,
U: 'static { ... }
}Expand description
Extension trait providing readonly bi-consumer composition methods for closures
Provides and_then and other composition methods for all closures
implementing Fn(&T, &U), enabling direct method chaining on closures
without explicit wrapper types.
§Features
- Natural Syntax: Chain operations directly on closures
- Returns BoxReadonlyBiConsumer: Composition results can be further chained
- Zero Cost: No overhead when composing closures
- Automatic Implementation: All
Fn(&T, &U)closures get these methods automatically
§Examples
use prism3_function::{ReadonlyBiConsumer, FnReadonlyBiConsumerOps};
let chained = (|x: &i32, y: &i32| {
println!("First: {}, {}", x, y);
}).and_then(|x: &i32, y: &i32| {
println!("Second: sum = {}", x + y);
});
chained.accept(&5, &3);§Author
Haixing Hu
Provided Methods§
Sourcefn and_then<C>(self, next: C) -> BoxReadonlyBiConsumer<T, U>where
Self: 'static,
C: ReadonlyBiConsumer<T, U> + 'static,
T: 'static,
U: 'static,
fn and_then<C>(self, next: C) -> BoxReadonlyBiConsumer<T, U>where
Self: 'static,
C: ReadonlyBiConsumer<T, U> + 'static,
T: 'static,
U: 'static,
Chains another readonly bi-consumer in sequence
Returns a new consumer executing the current operation first, then
the next operation. Consumes the current closure and returns
BoxReadonlyBiConsumer<T, U>.
§Type Parameters
C- The type of the next consumer
§Parameters
next- The consumer to execute after the current operation
§Returns
Returns the composed BoxReadonlyBiConsumer<T, U>
§Examples
use prism3_function::{ReadonlyBiConsumer, FnReadonlyBiConsumerOps};
let chained = (|x: &i32, y: &i32| {
println!("First: {}, {}", x, y);
}).and_then(|x: &i32, y: &i32| {
println!("Second: sum = {}", x + y);
}).and_then(|x: &i32, y: &i32| {
println!("Third: product = {}", x * y);
});
chained.accept(&5, &3);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.