Skip to main content

IntoResponse

Trait IntoResponse 

Source
pub trait IntoResponse {
    // Required method
    fn into_response(self) -> Response;
}
Expand description

Anything a handler is allowed to return.

This is what lets a handler return a &str, a Json, a Result, or a full Response without wrapping it by hand.

Required Methods§

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl IntoResponse for &str

Source§

impl IntoResponse for ()

Source§

impl IntoResponse for Error

A framework error renders as the development error page, or a generic 500 in production.

Source§

impl IntoResponse for Error

An I/O failure in a handler is a server error; carried separately because std::io::Error cannot implement a foreign trait here.

Source§

impl IntoResponse for Json

Source§

impl IntoResponse for String

Source§

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

? in a handler works for any error that knows how to become a response.

This is what lets validation return a 422 with its own JSON body while a framework error still reaches the error page: each error type decides how it is rendered, rather than everything collapsing into a 500.

Source§

impl<T: IntoResponse> IntoResponse for (u16, T)

Source§

impl<T: IntoResponse> IntoResponse for Option<T>

None becomes a 404, which makes req.param_as::<i64>("id")? style lookups read naturally in a handler.

Implementors§