pub trait ResultExt<T, E> {
// Required methods
fn tap_mut(self, f: impl FnOnce(&mut T)) -> Result<T, E>;
fn tap_err_mut(self, f: impl FnOnce(&mut E)) -> Result<T, E>;
fn swap(self) -> Result<E, T>;
}
Expand description
Extension methods for std::result::Result
.
Required Methods§
Sourcefn tap_mut(self, f: impl FnOnce(&mut T)) -> Result<T, E>
fn tap_mut(self, f: impl FnOnce(&mut T)) -> Result<T, E>
Tap into a Result
and modify its Ok
value.
This method captures the Result
in order not to break the caller-chain.
§Example
use rs_std_ext::result::ResultExt;
let mut x: Result<String, usize> = Ok("4".into());
assert_eq!(x.tap_mut(|s| s.push('2')), Ok("42".into()));
Sourcefn tap_err_mut(self, f: impl FnOnce(&mut E)) -> Result<T, E>
fn tap_err_mut(self, f: impl FnOnce(&mut E)) -> Result<T, E>
Tap into a Result
and modify its Err
value.
This method captures the Result
in order not to break the caller-chain.
§Example
use rs_std_ext::result::ResultExt;
let mut x: Result<String, usize> = Err(40);
assert_eq!(x.tap_err_mut(|s| *s += 2), Err(42));
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.