Responder

Trait Responder 

Source
pub trait Responder {
    // Required method
    fn response_to(self, req: &RequestContext<'_, '_>) -> Response<ResponseBody>;
}
Expand description

A trait for types that can be converted into HTTP responses.

Types implementing this trait can be returned directly from request handlers and will be automatically converted into HTTP responses.

Required Methods§

Implementations on Foreign Types§

Source§

impl Responder for &'static str

Implementation for static strings returns them as plain text responses.

Source§

impl Responder for Infallible

Source§

impl Responder for ParseError

Responder implementation for ParseError to convert parsing errors to responses

Source§

impl Responder for ()

Implementation for unit type () returns an empty response.

Source§

impl Responder for String

Implementation for String returns it as a plain text response.

Source§

impl<B> Responder for Response<B>
where B: Into<ResponseBody>,

Implementation for Response allows passing through pre-built responses. The response body is converted to the internal ResponseBody type.

Source§

impl<T: Responder> Responder for (StatusCode, T)

Implementation for (StatusCode, T) tuple allows setting a status code along with the response content.

Source§

impl<T: Responder> Responder for (T, StatusCode)

Implementation for (T, StatusCode) tuple - same as above but with reversed order.

Source§

impl<T: Responder> Responder for Option<T>

Implementation for Option allows handlers to return Option types. None case returns an empty response.

Source§

impl<T: Responder> Responder for Box<T>

Implementation for Box allows boxing responders.

Source§

impl<T: Responder, E: Responder> Responder for Result<T, E>

Implementation for Result allows handlers to return Result types directly. The Ok and Err variants must both implement Responder.

Implementors§

Source§

impl Responder for NotFound

Source§

impl<S> Responder for SseStream<S>
where S: Stream<Item = Event> + Send + 'static,