Why there is an implementation of IntoResponse for ()
#2845
-
SummaryJust as I mentioned in the title, I found this in axum: impl IntoResponse for () {
fn into_response(self) -> Response {
Body::empty().into_response()
}
} What if someone simply want's to return fn some_func() -> impl IntoResponse {
"success".into_response()
} but make a mistake like this: fn some_func() -> impl IntoResponse {
"success".into_response();
} then he/she will found this function always response a empty body with code 200 If someone want's to make a response with an empty body, he/she shoule use axum version0.7.5 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I guess this is a quality of life for simple handlers like Some tests use it for example like this: But I have to agree this might be something worth at least considering deprecating. In the meanwhile I'd suggest using a concrete return type rather than RPIT. This also shouldn't be an issue if you return from multiple places an make a mistake just once like fn some_func() -> impl IntoResponse { // ERROR: mismatched types expected struct `http::Response<body::Body>` found unit type `()`
if false {
return "failure".into_response();
}
"success".into_response();
} As a side note, since these types already implement |
Beta Was this translation helpful? Give feedback.
-
Once #2846 is merged and released, your example and similar code will generate a warning: |
Beta Was this translation helpful? Give feedback.
Once #2846 is merged and released, your example and similar code will generate a warning: