Crate respector

Source
Expand description

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.

§Examples

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)`.

Re-exports§

Modules§