[][src]Trait wyz::tap::TapDeref

pub trait TapDeref: Sized {
    fn tap_deref<F, R>(self, func: F) -> Self
    where
        Self: Deref,
        F: FnOnce(&Self::Target) -> R
, { ... }
fn tap_deref_dbg<F, R>(self, func: F) -> Self
    where
        Self: Deref,
        F: FnOnce(&Self::Target) -> R
, { ... }
fn tap_deref_mut<F, R>(self, func: F) -> Self
    where
        Self: DerefMut,
        F: FnOnce(&mut Self::Target) -> R
, { ... }
fn tap_deref_mut_dbg<F, R>(self, func: F) -> Self
    where
        Self: DerefMut,
        F: FnOnce(&mut Self::Target) -> R
, { ... } }

Dereferencing Tap

This trait runs the Deref or DerefMut trait on the caller, and passes the reborrowed dereference of it to the action. This permits passing methods defined on the supertype to the tap of a subtype by name, rather than by using closure syntax.

Note that the implementation of this trait does not require that the implementor also implement Deref or DerefMut, but the trait methods will cause compiler failures at the call site if the Deref or DerefMut traits are not present.

Examples

use wyz::tap::{Tap, TapDeref};
let v = vec![5, 1, 4, 2, 3]
  .tap_deref_mut(<[i32]>::sort)
  .tap_mut(|v| v.reverse());
assert_eq!(&v, &[5, 4, 3, 2, 1]);

Provided methods

fn tap_deref<F, R>(self, func: F) -> Self where
    Self: Deref,
    F: FnOnce(&Self::Target) -> R, 

Immutably dereferences self for inspection.

fn tap_deref_dbg<F, R>(self, func: F) -> Self where
    Self: Deref,
    F: FnOnce(&Self::Target) -> R, 

Calls tap_deref in debug builds, and does nothing in release builds.

fn tap_deref_mut<F, R>(self, func: F) -> Self where
    Self: DerefMut,
    F: FnOnce(&mut Self::Target) -> R, 

Mutably dereferences self for modification.

fn tap_deref_mut_dbg<F, R>(self, func: F) -> Self where
    Self: DerefMut,
    F: FnOnce(&mut Self::Target) -> R, 

Calls tap_deref_mut in debug builds, and does nothing in release builds.

Loading content...

Implementors

impl<T: Sized> TapDeref for T[src]

Loading content...