Skip to main content

ErrorExt

Trait ErrorExt 

Source
pub trait ErrorExt<T> {
    // Required methods
    fn bad_request(self) -> HttpResult<T>;
    fn unauthorized(self) -> HttpResult<T>;
    fn forbidden(self) -> HttpResult<T>;
    fn not_found(self) -> HttpResult<T>;
    fn internal_error(self) -> HttpResult<T>;
    fn with_http_error(self, error: HttpError) -> HttpResult<T>;
    fn map_http_error<F>(self, f: F) -> HttpResult<T>
       where F: FnOnce(String) -> HttpError;
}
Expand description

错误扩展 trait

为 Result 类型提供便捷的错误转换方法。

Required Methods§

Source

fn bad_request(self) -> HttpResult<T>

将错误转换为 HTTP 错误请求错误 (400)

Source

fn unauthorized(self) -> HttpResult<T>

将错误转换为 HTTP 未授权错误 (401)

Source

fn forbidden(self) -> HttpResult<T>

将错误转换为 HTTP 禁止访问错误 (403)

Source

fn not_found(self) -> HttpResult<T>

将错误转换为 HTTP 资源未找到错误 (404)

Source

fn internal_error(self) -> HttpResult<T>

将错误转换为 HTTP 内部服务器错误 (500)

Source

fn with_http_error(self, error: HttpError) -> HttpResult<T>

使用自定义错误消息转换为 HTTP 错误

Source

fn map_http_error<F>(self, f: F) -> HttpResult<T>
where F: FnOnce(String) -> HttpError,

使用错误消息转换函数

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.

Implementations on Foreign Types§

Source§

impl<T, E: Display> ErrorExt<T> for Result<T, E>

Implementors§