Trait HttpContext

Source
pub trait HttpContext<T> {
    // Required methods
    fn http_context<C>(
        self,
        status_code: StatusCode,
        extra_msg: C,
    ) -> Result<T, HttpError>
       where C: Display + Send + Sync + 'static;
    fn http_error<C>(self, extra_msg: C) -> Result<T, HttpError>
       where C: Display + Send + Sync + 'static;
}
Expand description

Easily convert std::result::Result to HttpResult

§Example

fn handler() -> HttpResult<()> {
    result.http_context(StatusCode::BAD_REQUEST, "bad request")?;   
    result.http_error("bad request")?;

    Ok(())
}

Required Methods§

Source

fn http_context<C>( self, status_code: StatusCode, extra_msg: C, ) -> Result<T, HttpError>
where C: Display + Send + Sync + 'static,

Source

fn http_error<C>(self, extra_msg: C) -> Result<T, HttpError>
where C: Display + Send + Sync + 'static,

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> HttpContext<T> for Result<T, E>
where E: Debug + Sync + Send + 'static,

Source§

fn http_context<C>( self, status_code: StatusCode, extra_msg: C, ) -> Result<T, HttpError>
where C: Display + Send + Sync + 'static,

Source§

fn http_error<C>(self, extra_msg: C) -> Result<T, HttpError>
where C: Display + Send + Sync + 'static,

Implementors§