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

Required Associated Types§

source

type Val: ?Sized

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

Required Methods§

source

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.

source

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.

source

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§

source

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

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

source

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.

source

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

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

Implementations on Foreign Types§

source§

impl<T> TapOptional for Option<T>

§

type Val = T

source§

fn tap_some(self, func: impl FnOnce(&T)) -> Self

source§

fn tap_some_mut(self, func: impl FnOnce(&mut T)) -> Self

source§

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

Implementors§