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 &/&mut borrows
  • the Borrow and BorrowMut traits
  • the AsRef and AsMut traits
  • the Deref and DerefMut traits

Provided methods

Pipes a reference into a function that cannot ordinarily be called in suffix position.

Parameters
  • &self: A reference to any value. .pipe_ref takes it by reference so that the .pipe_ref call will not artificially truncate the lifetime of self.
  • func: Any function, which receives &self as its first and only parameter. This function may return any value, including a borrow of self, as long as it has an equal or greater lifetime than self.
Type Parameters
  • R: The return value of func. This must have a lifetime of at least 'a, up to and including 'static and unconstrained (borrow-less value).
Lifetimes
  • 'a: The lifetime of the self value. .pipe_ref borrows self for the duration 'a, and extends it through the return value of func.

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_mut takes it by reference so that the .pipe_mut call will not artificially truncate the lifetime of self.
  • func: Any function, which receives &mut self as its first and only parameter. This funtion may return any value, including a borrow of self, as long as it has an equal or greater lifetime than self.
Type Parameters
  • R: The return value of func. This must have a lifetime of at least 'a, up to and including 'static and unconstrained (borrow-less value).
Lifetimes
  • 'a: The lifetime of the self value. .pipe_mut borrows self for the duration 'a, and extends it through the return value of func.

Implementors