Trait pingora_error::OrErr

source ·
pub trait OrErr<T, E> {
    // Required methods
    fn or_err(self, et: ErrorType, context: &'static str) -> Result<T, BError>
       where E: Into<Box<dyn ErrorTrait + Send + Sync>>;
    fn or_err_with<C: Into<ImmutStr>, F: FnOnce() -> C>(
        self,
        et: ErrorType,
        context: F
    ) -> Result<T, BError>
       where E: Into<Box<dyn ErrorTrait + Send + Sync>>;
    fn explain_err<C: Into<ImmutStr>, F: FnOnce(E) -> C>(
        self,
        et: ErrorType,
        context: F
    ) -> Result<T, BError>;
}
Expand description

Helper trait to chain errors with context

Required Methods§

source

fn or_err(self, et: ErrorType, context: &'static str) -> Result<T, BError>
where E: Into<Box<dyn ErrorTrait + Send + Sync>>,

Wrap the E in Result with new ErrorType and context, the existing E will be the cause.

This is a shortcut for map_err() + because()

source

fn or_err_with<C: Into<ImmutStr>, F: FnOnce() -> C>( self, et: ErrorType, context: F ) -> Result<T, BError>
where E: Into<Box<dyn ErrorTrait + Send + Sync>>,

Similar to or_err(), but takes a closure, which is useful for constructing String.

source

fn explain_err<C: Into<ImmutStr>, F: FnOnce(E) -> C>( self, et: ErrorType, context: F ) -> Result<T, BError>

Replace the E in Result with a new Error generated from the current error

This is useful when the current error cannot move out of scope. This is a shortcut for map_err() + explain().

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T, E> OrErr<T, E> for Result<T, E>