Trait ResultExt

Source
pub trait ResultExt<T, E>: Sized {
    // Required methods
    fn wrap_err<F, E2>(self, f: F) -> Result<T, E2>
       where F: FnOnce() -> E2;
    fn with_context(self, context: &'static str) -> Result<T>
       where E: Into<Error>;
    fn with_message(self, message: impl Into<String>) -> Result<T>
       where E: Into<Error>;
}
Expand description

Extension trait for Result types

Required Methods§

Source

fn wrap_err<F, E2>(self, f: F) -> Result<T, E2>
where F: FnOnce() -> E2,

Wrap an error with additional context

Source

fn with_context(self, context: &'static str) -> Result<T>
where E: Into<Error>,

Add context to an error when converting to Error

Source

fn with_message(self, message: impl Into<String>) -> Result<T>
where E: Into<Error>,

Add message to an error when converting to Error

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, E> ResultExt<T, E> for Result<T, E>

Source§

fn wrap_err<F, E2>(self, f: F) -> Result<T, E2>
where F: FnOnce() -> E2,

Source§

fn with_context(self, context: &'static str) -> Result<T>
where E: Into<Error>,

Source§

fn with_message(self, message: impl Into<String>) -> Result<T>
where E: Into<Error>,

Implementors§