Skip to main content

IntoResponse

Trait IntoResponse 

Source
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§

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).

Source§

impl IntoResponse for String

200 OK, text/plain (18.28.0).

Source§

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

Ok and Err each become their own response, so a handler can return Result<Json<Post>, AppError> (18.28.0).

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).

Implementors§

Source§

impl IntoResponse for AppError

Source§

impl IntoResponse for Response

Source§

impl<T> IntoResponse for Json<T>
where T: Serialize,

A handler may return Json<T> (18.28.0): 200 OK, application/json.