Trait aitch::Responder[][src]

pub trait Responder: Send + 'static {
    type Body: Body;
    fn into_response(self) -> BoxedResponse;
}

A Responder is any type which is returned from a request Handler.

This trait exists so that the ergonomics of writing Handler functions are nicer, as they can return an impl Responder type, which is automatically inferred based on the body of the function.

The Responder trait is automatically implemented for any type which implements:

This example is not tested
IntoFuture<Item = http::Response<impl Body>, Error: impl Into<aitch::Error>>

Importantly, this means it is implemented for the following types:

  • http::Result<http::Reponse<impl Body>>, which is the result of calling http::response::Builder::body(...) inside of a Handler.
  • A Future which eventually yields a http::Response<impl Body>.

As this implementation is done through a blanket impl for any T, it is unlikely that downstream crates will be able to implement Responder for any custom types. Downstream crates should instead ensure that their types implement IntoFuture (with the appropriate constraints), to ensure that they can make use of the Responder impl provided by aitch.

Associated Types

Required Methods

Converts the response into a BoxedResponse.

Implementors