[−][src]Trait inspector::ResultInspector
ResultInspector
makes it easier to examine the content of the Result
object.
Required methods
fn inspect<F>(self, f: F) -> Result<T, E> where
F: FnMut(&T),
F: FnMut(&T),
Do something with Result
's item, passing the value on.
When using Result
, you'll often chain several combinators together.
While working on such code, you might want to check out what's happening
at various parts in the pipeline. To do that, insert a call to inspect().
It's more common for inspect() to be used as a debugging tool than to exist
in your final code, but applications may find it useful in certain situations
when data needs to be logged before being manipulated.
See also std::iter::Iterator::inspect
ResultInspector::inspect()
only acts on the Ok(_)
variant of the Result
object
and does nothing when it is Err(_)
.
let env = std::env::var("XXX").inspect(|env| info!("Env var XXX is {:?}", env));
fn inspect_err<F>(self, f: F) -> Result<T, E> where
F: FnMut(&E),
F: FnMut(&E),
Same as ResultInspector::inspect()
, but only acts on Err(_)
variant.
let env = std::env::var("XXX") .inspect_err(|err| error!("Failed to get env var XXX: {:?}", err)) .unwrap_or_else(|_| String::new());
fn debug(self) -> Result<T, E>
Convenience wrapper for having a quick debug print out of your item.
It is equivalent to calling inspect(|item| println!("{:?}", item))
.
let env = std::env::var("XXX").debug();
Implementations on Foreign Types
impl<T, E> ResultInspector<T, E> for Result<T, E> where
T: Debug,
[src]
T: Debug,
fn inspect<F>(self, f: F) -> Self where
F: FnMut(&T),
[src]
F: FnMut(&T),
fn inspect_err<F>(self, f: F) -> Self where
F: FnMut(&E),
[src]
F: FnMut(&E),