pub trait AsyncResultExt<T, E>: Future<Output = Result<T, E>> + Sized {
// Provided method
fn with_context<C>(self, ctx: C) -> WithContext<Self, E, C> ⓘ
where C: FnOnce(&E) -> String { ... }
}Expand description
Extension trait providing a .with_context() method for futures resolving to Result<T, E>.
This method allows attaching additional context to errors lazily, by supplying a closure that is only executed if the future resolves to an error.
§Example
some_async_fn()
.with_context(|err| format!("Failed due to: {}", err))
.await;Provided Methods§
Sourcefn with_context<C>(self, ctx: C) -> WithContext<Self, E, C> ⓘ
fn with_context<C>(self, ctx: C) -> WithContext<Self, E, C> ⓘ
Adds context to an error produced by this future lazily.
The closure ctx is called only if the future resolves to an error, producing
a string context to be attached to the error.
§Parameters
ctx: closure to create context string from error reference
§Returns
A future that resolves to Result<T, AsyncError<E>>, where errors are wrapped to include context.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".