Trait tap::TapOptional
source · pub trait TapOptionalwhere
Self: Sized,{
type Val: ?Sized;
// Required methods
fn tap_some(self, func: impl FnOnce(&Self::Val)) -> Self;
fn tap_some_mut(self, func: impl FnOnce(&mut Self::Val)) -> Self;
fn tap_none(self, func: impl FnOnce()) -> Self;
// Provided methods
fn tap_some_dbg(self, func: impl FnOnce(&Self::Val)) -> Self { ... }
fn tap_some_mut_dbg(self, func: impl FnOnce(&mut Self::Val)) -> Self { ... }
fn tap_none_dbg(self, func: impl FnOnce()) -> Self { ... }
}
Expand description
Optional tapping, conditional on the optional presence of a value.
This trait is intended for use on types that express the concept of “optional
presence”, primarily the Option
monad. It provides taps that inspect the
container to determine if the effect function should execute or not.
Note: This trait is a specialization of
TapFallible
, and exists because thestd::ops::Try
trait is still unstable. WhenTry
stabilizes, this trait can be removed, andTapFallible
blanket-applied to allTry
implementors.
Required Associated Types§
Required Methods§
sourcefn tap_some(self, func: impl FnOnce(&Self::Val)) -> Self
fn tap_some(self, func: impl FnOnce(&Self::Val)) -> Self
Immutabily accesses an interior value only when it is present.
This function is identical to Tap::tap
, except that it is required
to check the implementing container for value presence before running.
Implementors must not run the effect function if the container is marked
as being empty.
sourcefn tap_some_mut(self, func: impl FnOnce(&mut Self::Val)) -> Self
fn tap_some_mut(self, func: impl FnOnce(&mut Self::Val)) -> Self
Mutably accesses an interor value only when it is present.
This function is identical to Tap::tap_mut
, except that it is
required to check the implementing container for value presence before
running. Implementors must not run the effect function if the container
is marked as being empty.
sourcefn tap_none(self, func: impl FnOnce()) -> Self
fn tap_none(self, func: impl FnOnce()) -> Self
Runs an effect function when the container is empty.
This function is identical to Tap::tap
, except that it is required
to check the implementing container for value absence before running.
Implementors must not run the effect function if the container is marked
as being non-empty.
Provided Methods§
sourcefn tap_some_dbg(self, func: impl FnOnce(&Self::Val)) -> Self
fn tap_some_dbg(self, func: impl FnOnce(&Self::Val)) -> Self
Calls .tap_some()
only in debug builds, and is erased in release
builds.
sourcefn tap_some_mut_dbg(self, func: impl FnOnce(&mut Self::Val)) -> Self
fn tap_some_mut_dbg(self, func: impl FnOnce(&mut Self::Val)) -> Self
Calls .tap_some_mut()
only in debug builds, and is erased in release
builds.
sourcefn tap_none_dbg(self, func: impl FnOnce()) -> Self
fn tap_none_dbg(self, func: impl FnOnce()) -> Self
Calls .tap_none()
only in debug builds, and is erased in release
builds.