tap::prelude

Trait TapOptional

Source
pub trait TapOptional
where 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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T> TapOptional for Option<T>

Source§

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§