pub trait StdResultExt<T, E> {
// Required methods
fn std_context(self, context: impl Display) -> Result<T, AnyError>;
fn with_std_context<F, C>(self, context: F) -> Result<T, AnyError>
where F: FnOnce(&E) -> C,
C: Display;
fn anyerr(self) -> Result<T, AnyError>;
}Expand description
Provides extension methods to add context to std errors.
You should only call these methods on results that contain errors which do not implement StackError.
For results with StackErrors, instead use the methods from StackResultExt. The latter will
preserve call-site metadata, whereas using the methods from the StdResultExt will lose the
call-site metadata when called on a StackError result.
Required Methods§
Sourcefn std_context(self, context: impl Display) -> Result<T, AnyError>
fn std_context(self, context: impl Display) -> Result<T, AnyError>
Converts the result’s error value to AnyError while providing additional context.
Sourcefn with_std_context<F, C>(self, context: F) -> Result<T, AnyError>
fn with_std_context<F, C>(self, context: F) -> Result<T, AnyError>
Converts the result’s error value to AnyError while providing lazily-evaluated additional context.
The context closure is only invoked if an error occurs.
Sourcefn anyerr(self) -> Result<T, AnyError>
fn anyerr(self) -> Result<T, AnyError>
Converts the result’s error into AnyError.
You should make sure to only call this on results that contain an error which does not
implement StackError. If it does implement StackError you can simply convert
the result’s error to AnyError with the ? operator. If you use anyerr on
StackErrors, you will lose access to the error’s call-site metadata.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.