pub trait TapFalliblewhere
Self: Sized,{
type Ok: ?Sized;
type Err: ?Sized;
// Required methods
fn tap_ok(self, func: impl FnOnce(&Self::Ok)) -> Self;
fn tap_ok_mut(self, func: impl FnOnce(&mut Self::Ok)) -> Self;
fn tap_err(self, func: impl FnOnce(&Self::Err)) -> Self;
fn tap_err_mut(self, func: impl FnOnce(&mut Self::Err)) -> Self;
// Provided methods
fn tap_ok_dbg(self, func: impl FnOnce(&Self::Ok)) -> Self { ... }
fn tap_ok_mut_dbg(self, func: impl FnOnce(&mut Self::Ok)) -> Self { ... }
fn tap_err_dbg(self, func: impl FnOnce(&Self::Err)) -> Self { ... }
fn tap_err_mut_dbg(self, func: impl FnOnce(&mut Self::Err)) -> Self { ... }
}
Expand description
Fallible tapping, conditional on the optional success of an expression.
This trait is intended for use on types that express the concept of “fallible
presence”, primarily the Result
monad. It provides taps that inspect the
container to determine if the effect function should execute or not.
Note: This trait would ideally be implemented as a blanket over all
std::ops::Try
implementors. WhenTry
stabilizes, this crate can be updated to do so.
Required Associated Types§
Required Methods§
Sourcefn tap_ok(self, func: impl FnOnce(&Self::Ok)) -> Self
fn tap_ok(self, func: impl FnOnce(&Self::Ok)) -> Self
Immutably accesses an interior success value.
This function is identical to Tap::tap
, except that it is required
to check the implementing container for value success before running.
Implementors must not run the effect function if the container is marked
as being a failure.
Sourcefn tap_ok_mut(self, func: impl FnOnce(&mut Self::Ok)) -> Self
fn tap_ok_mut(self, func: impl FnOnce(&mut Self::Ok)) -> Self
Mutably accesses an interior success value.
This function is identical to Tap::tap_mut
, except that it is
required to check the implementing container for value success before
running. Implementors must not run the effect function if the container
is marked as being a failure.
Sourcefn tap_err(self, func: impl FnOnce(&Self::Err)) -> Self
fn tap_err(self, func: impl FnOnce(&Self::Err)) -> Self
Immutably accesses an interior failure value.
This function is identical to Tap::tap
, except that it is required
to check the implementing container for value failure before running.
Implementors must not run the effect function if the container is marked
as being a success.
Sourcefn tap_err_mut(self, func: impl FnOnce(&mut Self::Err)) -> Self
fn tap_err_mut(self, func: impl FnOnce(&mut Self::Err)) -> Self
Mutably accesses an interior failure value.
This function is identical to Tap::tap_mut
, except that it is
required to check the implementing container for value failure before
running. Implementors must not run the effect function if the container
is marked as being a success.
Provided Methods§
Sourcefn tap_ok_dbg(self, func: impl FnOnce(&Self::Ok)) -> Self
fn tap_ok_dbg(self, func: impl FnOnce(&Self::Ok)) -> Self
Calls .tap_ok()
only in debug builds, and is erased in release builds.
Sourcefn tap_ok_mut_dbg(self, func: impl FnOnce(&mut Self::Ok)) -> Self
fn tap_ok_mut_dbg(self, func: impl FnOnce(&mut Self::Ok)) -> Self
Calls .tap_ok_mut()
only in debug builds, and is erased in release
builds.
Sourcefn tap_err_dbg(self, func: impl FnOnce(&Self::Err)) -> Self
fn tap_err_dbg(self, func: impl FnOnce(&Self::Err)) -> Self
Calls .tap_err()
only in debug builds, and is erased in release
builds.
Sourcefn tap_err_mut_dbg(self, func: impl FnOnce(&mut Self::Err)) -> Self
fn tap_err_mut_dbg(self, func: impl FnOnce(&mut Self::Err)) -> Self
Calls .tap_err_mut()
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.