Trait ResultExt

Source
pub trait ResultExt {
    type Item;

    // Required methods
    fn map_status(self, status_code: StatusCode) -> Result<Self::Item>;
    fn map_http_error<S>(
        self,
        status_code: StatusCode,
        reason: S,
    ) -> Result<Self::Item>
       where S: Into<Cow<'static, str>>;
}
Expand description

Extension trait to map the error variant of a Result to a HttpError.

Required Associated Types§

Required Methods§

Source

fn map_status(self, status_code: StatusCode) -> Result<Self::Item>

Maps a Result<T, E> to Result<T, HttpError<R>> by creating a HttpError with the specified status code wrapping the error contained Err.

§Example

let err = "nan".parse::<i32>()
    .map_status(StatusCode::BAD_REQUEST)
    .unwrap_err();
assert_eq!(HttpError::from(err).status_code(), StatusCode::BAD_REQUEST);
Source

fn map_http_error<S>( self, status_code: StatusCode, reason: S, ) -> Result<Self::Item>
where S: Into<Cow<'static, str>>,

Maps a Result<T, E> to Result<T, HttpError<R>> by creating a HttpError with the specified status code and reason wrapping the error contained Err.

§Example

let err = "nan".parse::<i32>()
    .map_http_error(StatusCode::BAD_REQUEST, "invalid number")
    .unwrap_err();
let http_err = HttpError::from(err);
assert_eq!(http_err.status_code(), StatusCode::BAD_REQUEST);
assert_eq!(http_err.reason().unwrap(), "invalid number");

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<E, T> ResultExt for Result<T, E>
where E: Into<Error> + Send + Sync + 'static,

Source§

type Item = T

Source§

fn map_status(self, status_code: StatusCode) -> Result<T>

Source§

fn map_http_error<S>( self, status_code: StatusCode, reason: S, ) -> Result<Self::Item>
where S: Into<Cow<'static, str>>,

Implementors§