pub trait TapDeref: Sized {
fn tap_deref<F, R>(self, func: F) -> Self
where
Self: Deref,
F: FnOnce(&<Self as Deref>::Target) -> R,
{ ... }
fn tap_deref_dbg<F, R>(self, func: F) -> Self
where
Self: Deref,
F: FnOnce(&<Self as Deref>::Target) -> R,
{ ... }
fn tap_deref_mut<F, R>(self, func: F) -> Self
where
Self: DerefMut,
F: FnOnce(&mut <Self as Deref>::Target) -> R,
{ ... }
fn tap_deref_mut_dbg<F, R>(self, func: F) -> Self
where
Self: DerefMut,
F: FnOnce(&mut <Self as Deref>::Target) -> R,
{ ... }
}
Expand description
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
Immutably dereferences self
for inspection.
Calls tap_deref
in debug builds, and does nothing in release builds.
Mutably dereferences self
for modification.