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
Methods on any Result for giving its error an HTTP status code, and for changing the
status code or body of an error that already has one.
Each method only changes the Err value. Ok values pass through unchanged.
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 in the status code S. The error becomes the body.
§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>>
Like with_status, but first converts the error into
E2 with Into::into.
E2 can often be inferred, as in into_status::<BadRequest, _>().
§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,
Replaces the error’s status code with S, keeping the body.
§Example
let result: Result<(), Forbidden<String>> = Err(Forbidden("hidden".into()));
// Has type `Result<(), NotFound<String>>`
let _changed = result.change_status::<NotFound>();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>>
Applies f to the error’s body, keeping the status code.
§Example
let result: Result<(), Internal<String>> = Err(Internal("error".into()));
// Has type `Result<(), Internal<Json<String>>>`
let _mapped = result.map_status(Json);Provided Methods§
Sourcefn map_status_into<O>(self) -> Result<T, E::WithInner<O>>
fn map_status_into<O>(self) -> Result<T, E::WithInner<O>>
Converts the error’s body with Into::into, keeping the status code.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".