Trait devela::ops::Apply

source ·
pub trait Apply<Res> {
    // Provided methods
    fn apply<F: FnOnce(Self) -> Res>(self, f: F) -> Res
       where Self: Sized { ... }
    fn apply_ref<F: FnOnce(&Self) -> Res>(&self, f: F) -> Res { ... }
    fn apply_mut<F: FnOnce(&mut Self) -> Res>(&mut self, f: F) -> Res { ... }
}
Expand description

Allows to chain free functions into method call chains.

Examples

use devela::ops::Apply;

let s = 1
    .apply(|s| s * 2)
    .apply(|s| s + 1)
    .apply(|s: i32| s.to_string());
assert_eq![s, 3.to_string()];
use devela::ops::Apply;

// We can sort it, but we don't receive the new vec.
let v: Vec<i32> = vec![3, 2, 1, 5].apply_mut(|it| it.sort());

Provided Methods§

source

fn apply<F: FnOnce(Self) -> Res>(self, f: F) -> Reswhere Self: Sized,

Apply a function which takes the parameter by value.

source

fn apply_ref<F: FnOnce(&Self) -> Res>(&self, f: F) -> Res

Apply a function which takes the parameter by shared reference.

source

fn apply_mut<F: FnOnce(&mut Self) -> Res>(&mut self, f: F) -> Res

Apply a function which takes the parameter by exclusive reference.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T: ?Sized, Res> Apply<Res> for T