[−][src]Trait err_context::ResultExt
Extension traits for results.
This provides method to enrich the error in the result with additional context. See the general principles and examples at the crate level documentation.
Usually, this trait isn't imported directly, but through the prelude
.
Required methods
fn context<M>(self, msg: M) -> Result<T, Context<M, E>> where
M: Display,
M: Display,
Wraps the error in another layer of context.
If the result is success, this does nothing. If it is error, it wraps the error in another
layer, in the same way as calling .context
on that error itself
would.
If the construction of the message is expensive, consider using
with_context
.
fn with_context<F, M>(self, f: F) -> Result<T, Context<M, E>> where
F: FnOnce(&E) -> M,
M: Display,
F: FnOnce(&E) -> M,
M: Display,
Wraps the error in another layer of context.
This works in a similar way as context
. However, the closure to
construct the context is called only in case the result is Err
, avoiding the construction
cost in the success case.
As the common usage goes, string literal can be passed directly with
context
, but calling format!
to construct the message would be
better done with this method.
Implementations on Foreign Types
impl<T, E: Error> ResultExt<T, E> for Result<T, E>
[src]
fn context<M>(self, msg: M) -> Result<T, Context<M, E>> where
M: Display,
[src]
M: Display,
fn with_context<F, M>(self, f: F) -> Result<T, Context<M, E>> where
F: FnOnce(&E) -> M,
M: Display,
[src]
F: FnOnce(&E) -> M,
M: Display,