orphanage 0.5.6

Random collection of stuff that is still searching for a home.
Documentation
pub trait PipeIf
where
  Self: Sized
{
  /// Pipe a value through a closure if `predicate` is `true`.
  #[inline]
  #[must_use]
  fn pipe_if<F>(self, predicate: bool, f: F) -> Self
  where
    F: FnOnce(Self) -> Self
  {
    if predicate { f(self) } else { self }
  }

  /// Optionally pipe a value through a closure.
  #[inline]
  #[must_use]
  fn pipe_opt<T, F>(self, opt: Option<T>, f: F) -> Self
  where
    F: FnOnce(Self, T) -> Self
  {
    if let Some(r) = opt { f(self, r) } else { self }
  }

  /// Optionally pipe a reference to a value through a closure.
  #[inline]
  #[must_use]
  fn pipe_optref<T, F>(self, opt: Option<&T>, f: F) -> Self
  where
    F: FnOnce(Self, &T) -> Self
  {
    if let Some(r) = opt { f(self, r) } else { self }
  }
}

impl<T> PipeIf for T {}

// vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :