Trait wyz::pipe::PipeRef [−][src]
pub trait PipeRef {
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where
R: 'a + Sized,
{ ... }
fn pipe_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where
R: 'a + Sized,
{ ... }
}Expand description
Referential piping.
The Pipe trait passes by value; the functions in this trait pass by reference.
As such, this trait is implemented on all types, not just Sized. The methods
in this trait operate by various mechanisms, including:
- normal
&/&mutborrows - the
BorrowandBorrowMuttraits - the
AsRefandAsMuttraits - the
DerefandDerefMuttraits
Provided methods
Pipes a reference into a function that cannot ordinarily be called in suffix position.
Parameters
&self: A reference to any value..pipe_reftakes it by reference so that the.pipe_refcall will not artificially truncate the lifetime ofself.func: Any function, which receives&selfas its first and only parameter. This function may return any value, including a borrow ofself, as long as it has an equal or greater lifetime thanself.
Type Parameters
R: The return value offunc. This must have a lifetime of at least'a, up to and including'staticand unconstrained (borrow-less value).
Lifetimes
'a: The lifetime of theselfvalue..pipe_refborrowsselffor the duration'a, and extends it through the return value offunc.
Pipes a mutable reference into a function that cannot ordinarily be called in suffix position.
Parameters
&mut self: A mutable reference to any value..pipe_muttakes it by reference so that the.pipe_mutcall will not artificially truncate the lifetime ofself.func: Any function, which receives&mut selfas its first and only parameter. This funtion may return any value, including a borrow ofself, as long as it has an equal or greater lifetime thanself.
Type Parameters
R: The return value offunc. This must have a lifetime of at least'a, up to and including'staticand unconstrained (borrow-less value).
Lifetimes
'a: The lifetime of theselfvalue..pipe_mutborrowsselffor the duration'a, and extends it through the return value offunc.