ResultExt

Trait ResultExt 

Source
pub trait ResultExt<T>: Sealed {
    // Required methods
    fn with_kind(self, kind: ErrorKind) -> Result<T, Error>
       where Self: Sized;
    fn with_context<C>(self, kind: ErrorKind, message: C) -> Result<T, Error>
       where Self: Sized,
             C: Into<Cow<'static, str>>;
    fn with_context_fn<F, C>(self, kind: ErrorKind, f: F) -> Result<T, Error>
       where Self: Sized,
             F: FnOnce() -> C,
             C: Into<Cow<'static, str>>;
}
Expand description

An extension to the Result type that easy allows creating Error values from existing errors.

This trait cannot be implemented on custom types and is meant for usage with Result.

Required Methods§

Source

fn with_kind(self, kind: ErrorKind) -> Result<T, Error>
where Self: Sized,

Creates a new error with the specified ErrorKind.

Source

fn with_context<C>(self, kind: ErrorKind, message: C) -> Result<T, Error>
where Self: Sized, C: Into<Cow<'static, str>>,

Creates a new error with the specified ErrorKind and an additional message.

Source

fn with_context_fn<F, C>(self, kind: ErrorKind, f: F) -> Result<T, Error>
where Self: Sized, F: FnOnce() -> C, C: Into<Cow<'static, str>>,

Creates a new error with the specified ErrorKind and a function that returns an additional message.

Implementations on Foreign Types§

Source§

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

Source§

fn with_kind(self, kind: ErrorKind) -> Result<T, Error>
where Result<T, E>: Sized,

Source§

fn with_context<C>(self, kind: ErrorKind, message: C) -> Result<T, Error>
where Result<T, E>: Sized, C: Into<Cow<'static, str>>,

Source§

fn with_context_fn<F, C>(self, kind: ErrorKind, f: F) -> Result<T, Error>
where Result<T, E>: Sized, F: FnOnce() -> C, C: Into<Cow<'static, str>>,

Implementors§