CallChainMut

Trait CallChainMut 

Source
pub trait CallChainMut {
    // Provided method
    fn chain_mut<R, F: FnOnce(&mut Self) -> R>(&mut self, f: F) -> &mut Self { ... }
}
Expand description

Enables mutable call chaining on all types.

§Example

use chainer::*;

struct Counter { value: i32 }
impl Counter {
    fn increment(&mut self) {
        self.value += 1;
        println!("{}", self.value);
    }
}

fn main() {
    Counter { value: 0 }
        .chain_mut(Counter::increment)
        .chain_mut(Counter::increment)
        .chain_mut(Counter::increment);

    // 1
    // 2
    // 3
}

Provided Methods§

Source

fn chain_mut<R, F: FnOnce(&mut Self) -> R>(&mut self, f: F) -> &mut Self

Enables mutable call chaining on all types.

§Example
use chainer::*;

struct Counter { value: i32 }
impl Counter {
    fn increment(&mut self) {
        self.value += 1;
        println!("{}", self.value);
    }
}

fn main() {
    Counter { value: 0 }
        .chain_mut(Counter::increment)
        .chain_mut(Counter::increment)
        .chain_mut(Counter::increment);

    // 1
    // 2
    // 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.

Implementors§

Source§

impl<T: ?Sized> CallChainMut for T