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§
sourcefn apply<F: FnOnce(Self) -> Res>(self, f: F) -> Reswhere
Self: Sized,
fn apply<F: FnOnce(Self) -> Res>(self, f: F) -> Reswhere Self: Sized,
Apply a function which takes the parameter by value.
Object Safety§
This trait is not object safe.