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>>;
}
Required Associated Types§
Required Methods§
Sourcefn map_status(self, status_code: StatusCode) -> Result<Self::Item>
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);
Sourcefn map_http_error<S>(
self,
status_code: StatusCode,
reason: S,
) -> Result<Self::Item>
fn map_http_error<S>( self, status_code: StatusCode, reason: S, ) -> Result<Self::Item>
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.