Trait ErrorContext

Source
pub trait ErrorContext<T> {
    // Required methods
    fn with_context_internal_error(
        self,
        message: impl FnOnce() -> String,
    ) -> Result<T, ApiError>;
    fn with_context_bad_request(
        self,
        message: impl FnOnce() -> String,
    ) -> Result<T, ApiError>;
    fn with_context_not_found(
        self,
        message: impl FnOnce() -> String,
    ) -> Result<T, ApiError>;

    // Provided methods
    fn context_internal_error(self, message: &str) -> Result<T, ApiError>
       where Self: Sized { ... }
    fn context_bad_request(self, message: &str) -> Result<T, ApiError>
       where Self: Sized { ... }
    fn context_not_found(self, message: &str) -> Result<T, ApiError>
       where Self: Sized { ... }
}

Required Methods§

Source

fn with_context_internal_error( self, message: impl FnOnce() -> String, ) -> Result<T, ApiError>

Make a new internal server error using the given function to create the message.

Source

fn with_context_bad_request( self, message: impl FnOnce() -> String, ) -> Result<T, ApiError>

Make a new bad request error using the given function to create the message.

Source

fn with_context_not_found( self, message: impl FnOnce() -> String, ) -> Result<T, ApiError>

Make a new not found error using the given function to create the message.

Provided Methods§

Source

fn context_internal_error(self, message: &str) -> Result<T, ApiError>
where Self: Sized,

Make a new internal server error with the given message.

Source

fn context_bad_request(self, message: &str) -> Result<T, ApiError>
where Self: Sized,

Make a new bad request error with the given message.

Source

fn context_not_found(self, message: &str) -> Result<T, ApiError>
where Self: Sized,

Make a new not found error with the given message.

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

Source§

fn with_context_internal_error( self, message: impl FnOnce() -> String, ) -> Result<T, ApiError>

Source§

fn with_context_bad_request( self, message: impl FnOnce() -> String, ) -> Result<T, ApiError>

Source§

fn with_context_not_found( self, message: impl FnOnce() -> String, ) -> Result<T, ApiError>

Source§

impl<T, E> ErrorContext<T> for Result<T, E>
where E: Error + 'static,

Source§

fn with_context_internal_error( self, message: impl FnOnce() -> String, ) -> Result<T, ApiError>

Source§

fn with_context_bad_request( self, message: impl FnOnce() -> String, ) -> Result<T, ApiError>

Source§

fn with_context_not_found( self, message: impl FnOnce() -> String, ) -> Result<T, ApiError>

Implementors§