[][src]Trait pipe_trait::Pipe

pub trait Pipe {
    fn pipe<Return>(self, f: impl FnOnce(Self) -> Return) -> Return
    where
        Self: Sized
, { ... }
fn pipe_ref<'a, Return>(
        &'a self,
        f: impl FnOnce(&'a Self) -> Return
    ) -> Return { ... }
fn pipe_mut<'a, Return>(
        &'a mut self,
        f: impl FnOnce(&'a mut Self) -> Return
    ) -> Return { ... } }

All sized types implement this trait.

Provided methods

fn pipe<Return>(self, f: impl FnOnce(Self) -> Return) -> Return where
    Self: Sized

Apply f to self.

assert_eq!(
    12.pipe(double).pipe(Foo),
    Foo(double(12)),
)

fn pipe_ref<'a, Return>(&'a self, f: impl FnOnce(&'a Self) -> Return) -> Return

Apply f to &self.

#[derive(Debug, PartialEq, Eq)]
struct Foo(i32);
let a = Foo(12);
let b = a
    .pipe_ref(|a| a.0) // a is not moved
    .pipe(Foo);
assert_eq!(a, b); // a is used again

fn pipe_mut<'a, Return>(
    &'a mut self,
    f: impl FnOnce(&'a mut Self) -> Return
) -> Return

Apply f to &mut self.

#[derive(Debug, PartialEq, Eq)]
struct Foo(i32, i32);
let mut a = Foo(0, 0);
a.pipe_mut(|a| a.0 = 12);
a.pipe_mut(|a| a.1 = 34);
assert_eq!(a, Foo(12, 34));
Loading content...

Implementors

impl<X> Pipe for X[src]

Loading content...