Trait tap::tap::TapOptional[][src]

pub trait TapOptional where
    Self: Sized
{ type Val: ?Sized; 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; 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 { ... } }

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 the std::ops::Try trait is still unstable. When Try stabilizes, this trait can be removed, and TapFallible blanket-applied to all Try implementors.

Associated Types

type Val: ?Sized[src]

The interior type that the container may or may not carry.

Loading content...

Required methods

fn tap_some(self, func: impl FnOnce(&Self::Val)) -> Self[src]

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.

fn tap_some_mut(self, func: impl FnOnce(&mut Self::Val)) -> Self[src]

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.

fn tap_none(self, func: impl FnOnce()) -> Self[src]

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.

Loading content...

Provided methods

fn tap_some_dbg(self, func: impl FnOnce(&Self::Val)) -> Self[src]

Calls .tap_some() only in debug builds, and is erased in release builds.

fn tap_some_mut_dbg(self, func: impl FnOnce(&mut Self::Val)) -> Self[src]

Calls .tap_some_mut() only in debug builds, and is erased in release builds.

fn tap_none_dbg(self, func: impl FnOnce()) -> Self[src]

Calls .tap_none() only in debug builds, and is erased in release builds.

Loading content...

Implementations on Foreign Types

impl<T> TapOptional for Option<T>[src]

type Val = T

Loading content...

Implementors

Loading content...