Trait anyhow_http::ResultExt
source · pub trait ResultExt {
type Item;
// Required methods
fn map_status(
self,
status_code: StatusCode,
) -> StdResult<Self::Item, HttpError>;
fn map_http_error<S>(
self,
status_code: StatusCode,
reason: S,
) -> StdResult<Self::Item, HttpError>
where S: Into<Cow<'static, str>>;
}Required Associated Types§
Required Methods§
sourcefn map_status(self, status_code: StatusCode) -> StdResult<Self::Item, HttpError>
fn map_status(self, status_code: StatusCode) -> StdResult<Self::Item, HttpError>
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
use http::StatusCode;
use anyhow_http::{http_error, HttpError, ResultExt};
let s: Result<i32, HttpError> = "nan"
.parse::<i32>()
.map_status(StatusCode::BAD_REQUEST);
assert_eq!(s, Err(http_error!(BAD_REQUEST)));sourcefn map_http_error<S>(
self,
status_code: StatusCode,
reason: S,
) -> StdResult<Self::Item, HttpError>
fn map_http_error<S>( self, status_code: StatusCode, reason: S, ) -> StdResult<Self::Item, HttpError>
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
use http::StatusCode;
use anyhow_http::{http_error, HttpError, ResultExt};
let s: Result<i32, HttpError> = "nan"
.parse::<i32>()
.map_http_error(StatusCode::BAD_REQUEST, "invalid number");
assert_eq!(s, Err(http_error!(BAD_REQUEST, "invalid number")));Object Safety§
This trait is not object safe.