Trait CallChain

Source
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§

Source

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.

Implementors§

Source§

impl<T: ?Sized> CallChain for T