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§
Sourcefn with_status<S>(self) -> Result<T, S::WithInner<E>>where
S: StatusProvider<Inner = ()>,
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>();Sourcefn into_status<S, E2>(self) -> Result<T, S::WithInner<E2>>
fn into_status<S, E2>(self) -> Result<T, S::WithInner<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>();Sourcefn change_status<S>(self) -> Result<T, S::WithInner<E::Inner>>where
E: StatusProvider,
S: StatusProvider,
fn change_status<S>(self) -> Result<T, S::WithInner<E::Inner>>where
E: StatusProvider,
S: StatusProvider,
Changes the status of the error to the given StatusProvider S, preserving the inner error.
Sourcefn map_status<F, O>(self, f: F) -> Result<T, E::WithInner<O>>
fn map_status<F, O>(self, f: F) -> Result<T, E::WithInner<O>>
Maps the inner state of the given StatusProvider using the provided function f.
Provided Methods§
Sourcefn map_status_into<O>(self) -> Result<T, E::WithInner<O>>
fn map_status_into<O>(self) -> Result<T, E::WithInner<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".