pub trait IntoResponse {
// Required method
fn into_response(self) -> Response;
}Expand description
Implemented by any type that can be turned into an HTTP Response.
Implement this on your application error enum so handlers can return
Result<Response, MyError> and the framework maps the error to the
correct HTTP status automatically.
Response itself implements IntoResponse as the identity conversion.
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 &'static str
200 OK, text/plain (18.28.0).
impl IntoResponse for &'static str
200 OK, text/plain (18.28.0).
fn into_response(self) -> Response
Source§impl IntoResponse for String
200 OK, text/plain (18.28.0).
impl IntoResponse for String
200 OK, text/plain (18.28.0).
fn into_response(self) -> Response
Source§impl<T, E> IntoResponse for Result<T, E>where
T: IntoResponse,
E: IntoResponse,
Ok and Err each become their own response, so a handler can return
Result<Json<Post>, AppError> (18.28.0).
impl<T, E> IntoResponse for Result<T, E>where
T: IntoResponse,
E: IntoResponse,
Ok and Err each become their own response, so a handler can return
Result<Json<Post>, AppError> (18.28.0).
fn into_response(self) -> Response
Source§impl<T> IntoResponse for (&'static StatusCodeReasonPhrase, T)where
T: IntoResponse,
The inner response with its status replaced:
(STATUS_CODE_REASON_PHRASE.n201_created, Json(post)) (18.28.0).
impl<T> IntoResponse for (&'static StatusCodeReasonPhrase, T)where
T: IntoResponse,
The inner response with its status replaced:
(STATUS_CODE_REASON_PHRASE.n201_created, Json(post)) (18.28.0).
fn into_response(self) -> Response
Implementors§
impl IntoResponse for AppError
impl IntoResponse for Response
impl<T> IntoResponse for Json<T>where
T: Serialize,
A handler may return Json<T> (18.28.0): 200 OK, application/json.