pingora_error

Trait OkOrErr

Source
pub trait OkOrErr<T> {
    // Required methods
    fn or_err(self, et: ErrorType, context: &'static str) -> Result<T, BError>;
    fn or_err_with<C: Into<ImmutStr>, F: FnOnce() -> C>(
        self,
        et: ErrorType,
        context: F,
    ) -> Result<T, BError>;
}
Expand description

Helper trait to convert an Option to an Error with context.

Required Methods§

Source

fn or_err(self, et: ErrorType, context: &'static str) -> Result<T, BError>

Source

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

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> OkOrErr<T> for Option<T>

Source§

fn or_err(self, et: ErrorType, context: &'static str) -> Result<T, BError>

Convert the Option to a new Error with ErrorType and context if None, Ok otherwise.

This is a shortcut for .ok_or(Error::explain())

Source§

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

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

Implementors§