Trait OkOrErr

Source
pub trait OkOrErr<T> {
    // Required methods
    fn ok_or_internal_err(self, reason: &'static str) -> Result<T>;
    fn ok_or_err(
        self,
        code: impl ErrorInfo + Send + Sync + 'static,
    ) -> Result<T>;
    fn ok_or_err_with(
        self,
        code: impl ErrorInfo + Send + Sync + 'static,
        reason: &'static str,
    ) -> Result<T>;
}
Expand description

Utility trait to map any Option<T> to a Result<T, Box<Error>>

Required Methods§

Source

fn ok_or_internal_err(self, reason: &'static str) -> Result<T>

Transforms the option into a Result, mapping None to an internal server error

Source

fn ok_or_err(self, code: impl ErrorInfo + Send + Sync + 'static) -> Result<T>

Transforms the option into a Result, mapping None to the given error

Source

fn ok_or_err_with( self, code: impl ErrorInfo + Send + Sync + 'static, reason: &'static str, ) -> Result<T>

Transforms the option into a Result, mapping None to the given error with a reason

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 ok_or_internal_err(self, reason: &'static str) -> Result<T>

Source§

fn ok_or_err(self, code: impl ErrorInfo + Send + Sync + 'static) -> Result<T>

Source§

fn ok_or_err_with( self, code: impl ErrorInfo + Send + Sync + 'static, reason: &'static str, ) -> Result<T>

Implementors§