pub trait CallChain {
// Provided method
fn chain<R, F: FnOnce(&Self) -> R>(&self, f: F) -> &Self { ... }
}
Expand description
Enables immutable call chaining on all types.
§Example
use chainer::*;
struct HelloWorld;
impl HelloWorld {
fn print(&self) {
println!("Hello, world!");
}
}
fn main() {
HelloWorld
.chain(HelloWorld::print)
.chain(HelloWorld::print)
.chain(HelloWorld::print);
// Hello, world!
// Hello, world!
// Hello, world!
}
Provided Methods§
Sourcefn chain<R, F: FnOnce(&Self) -> R>(&self, f: F) -> &Self
fn chain<R, F: FnOnce(&Self) -> R>(&self, f: F) -> &Self
Enables immutable call chaining on all types.
§Example
use chainer::*;
struct HelloWorld;
impl HelloWorld {
fn print(&self) {
println!("Hello, world!");
}
}
fn main() {
HelloWorld
.chain(HelloWorld::print)
.chain(HelloWorld::print)
.chain(HelloWorld::print);
// Hello, world!
// Hello, world!
// Hello, world!
}
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.