[][src]Trait pipe_trait::Pipe

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

All sized types implement this trait.

Provided methods

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

Apply f to self.

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

fn pipe_ref<'a, Return, Function>(&'a self, f: Function) -> Return where
    Function: FnOnce(&'a Self) -> 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, Function>(&'a mut self, f: Function) -> Return where
    Function: FnOnce(&'a mut Self) -> 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...