n0_error

Trait StdResultExt

Source
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§

Source

fn std_context(self, context: impl Display) -> Result<T, AnyError>

Converts the result’s error value to AnyError while providing additional context.

Source

fn with_std_context<F, C>(self, context: F) -> Result<T, AnyError>
where F: FnOnce(&E) -> C, C: Display,

Converts the result’s error value to AnyError while providing lazily-evaluated additional context.

The context closure is only invoked if an error occurs.

Source

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.

Implementations on Foreign Types§

Source§

impl<T> StdResultExt<T, NoneError> for Option<T>

Source§

fn std_context(self, context: impl Display) -> Result<T, AnyError>

Source§

fn with_std_context<F, C>(self, context: F) -> Result<T, AnyError>
where F: FnOnce(&NoneError) -> C, C: Display,

Source§

fn anyerr(self) -> Result<T, AnyError>

Source§

impl<T, E: Error + Send + Sync + 'static> StdResultExt<T, E> for Result<T, E>

Source§

fn std_context(self, context: impl Display) -> Result<T, AnyError>

Source§

fn with_std_context<F, C>(self, context: F) -> Result<T, AnyError>
where F: FnOnce(&E) -> C, C: Display,

Source§

fn anyerr(self) -> Result<T, AnyError>

Implementors§