Skip to main content

ResultStatusExt

Trait ResultStatusExt 

Source
pub trait ResultStatusExt<T, E>: Sized {
    // Required methods
    fn with_status<S>(self) -> Result<T, S::WithInner<E>>
       where S: StatusProvider<Inner = ()>;
    fn into_status<S, E2>(self) -> Result<T, S::WithInner<E2>>
       where S: StatusProvider<Inner = ()>,
             E: Into<E2>;
    fn change_status<S>(self) -> Result<T, S::WithInner<E::Inner>>
       where E: StatusProvider,
             S: StatusProvider;
    fn map_status<F, O>(self, f: F) -> Result<T, E::WithInner<O>>
       where E: StatusProvider,
             F: FnOnce(E::Inner) -> O;

    // Provided method
    fn map_status_into<O>(self) -> Result<T, E::WithInner<O>>
       where E: StatusProvider,
             E::Inner: Into<O> { ... }
}
Expand description

Extension trait for Result that provides methods to wrap errors with specific HTTP status codes.

Required Methods§

Source

fn with_status<S>(self) -> Result<T, S::WithInner<E>>
where S: StatusProvider<Inner = ()>,

Wraps the error E with the gives status S.

§Example

let result: Result<(), String> = Err("error".into());

// Has type `Result<(), BadRequest<String>>``
let _wrapped = result.with_status::<BadRequest>();
Source

fn into_status<S, E2>(self) -> Result<T, S::WithInner<E2>>
where S: StatusProvider<Inner = ()>, E: Into<E2>,

Wraps the error E with the gives status S, while converting the inner error-type using Into::into to E2.

Usually the second generic can be inferred by the compiler.

§Example

let result: Result<(), &str> = Err("error");

// Has type `Result<(), BadRequest<String>>`
let _wrapped = result.into_status::<BadRequest, String>();
Source

fn change_status<S>(self) -> Result<T, S::WithInner<E::Inner>>

Changes the status of the error to the given StatusProvider S, preserving the inner error.

Source

fn map_status<F, O>(self, f: F) -> Result<T, E::WithInner<O>>
where E: StatusProvider, F: FnOnce(E::Inner) -> O,

Maps the inner state of the given StatusProvider using the provided function f.

Provided Methods§

Source

fn map_status_into<O>(self) -> Result<T, E::WithInner<O>>
where E: StatusProvider, E::Inner: Into<O>,

Maps the inner error of the given StatusProvider using the Into::into conversion.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

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

Source§

fn into_status<S, E2>(self) -> Result<T, S::WithInner<E2>>
where S: StatusProvider<Inner = ()>, E: Into<E2>,

Source§

fn with_status<S>(self) -> Result<T, S::WithInner<E>>
where S: StatusProvider<Inner = ()>,

Source§

fn map_status<F, O>(self, f: F) -> Result<T, E::WithInner<O>>
where E: StatusProvider, F: FnOnce(E::Inner) -> O,

Source§

fn change_status<S>(self) -> Result<T, S::WithInner<E::Inner>>

Implementors§