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§
fn into_response(self) -> Response
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
impl IntoResponse for &str
fn into_response(self) -> Response
Source§impl IntoResponse for ()
impl IntoResponse for ()
fn into_response(self) -> Response
Source§impl IntoResponse for Error
A framework error renders as the development error page, or a generic 500
in production.
impl IntoResponse for Error
A framework error renders as the development error page, or a generic 500 in production.
fn into_response(self) -> Response
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.
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.
fn into_response(self) -> Response
Source§impl IntoResponse for Json
impl IntoResponse for Json
fn into_response(self) -> Response
Source§impl IntoResponse for String
impl IntoResponse for String
fn into_response(self) -> Response
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.
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.
fn into_response(self) -> Response
Source§impl<T: IntoResponse> IntoResponse for (u16, T)
impl<T: IntoResponse> IntoResponse for (u16, T)
fn into_response(self) -> Response
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.
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.