3 releases
0.1.2 | Apr 13, 2021 |
---|---|
0.1.1 | Mar 27, 2021 |
0.1.0 | Mar 25, 2021 |
#44 in #inspect
6KB
respector
An extension to add inspect
method to Option
and Result
types.
This allows doing something with the value contained in a Some
, an Ok
(with inspect
) or an Err
(with inspect_err
) while passing the value on,
which can be useful for introducing side effects in debugging, logging, etc.
Usage
use respector::prelude::*;
let some = Some(10);
assert_eq!(some.inspect(|x| println!("Some({})", x)), some); // Prints `Some(10)`.
let ok = Ok::<_, ()>(10);
assert_eq!(ok.inspect(|x| println!("Ok({})", x)), ok); // Prints `Ok(10)`.
let err = Err::<(), _>(10);
assert_eq!(Err(10).inspect_err(|x| println!("Err({})", x)), err); // Prints `Err(10)`.