3 ms·
Use https://docs.rs/axum/latest/axum/response/type.Response.html https://docs.rs/axum/latest/axum/response/type.Response.html This is also whats shown in the "
by davidpdrsn 4y ago
Use https://docs.rs/axum/latest/axum/response/type.Response.html https://docs.rs/axum/latest/axum/response/type.Response.html
This is also whats shown in the "Implementing IntoResponse" examples https://docs.rs/axum/latest/axum/response/trait.IntoResponse.html#implementing-intoresponse https://docs.rs/axum/latest/axum/response/trait.IntoResponse...
- rendaw 4y agoAh thanks! So `axum::response::Response` which is `http::Response<UnsyncBoxBody<Bytes, Error>>` is the fallback/catch-all response type, basically. I actually read that, but I didn't realize that it was a specific type and my IDE auto-probably imported the wrong one. There's a lot of types named `Response` and with how common re-exports are I probably wouldn't have noticed unless I was expecting it. And since they're all part of the same type tree you aren't going to get clear error messages from the compiler either. Naming it something like `DefaultResponse` or `AxumResponse` or calling it out explicitly by changing > Use Response for more low level control: to > The above all eventually gets turned into axum::response::Response (a specialization of `http::Response`), which you can instantiate directly for more low level control: would help immensely. Edit: No, reading more closely `Response` has a default body of `UnsyncBoxBody<Bytes, Error>` but other than that it's still generic and identical to `http::Response`? That's not going to help if you're having generic issues unless you explicitly convert things to `Bytes` AFAICT, and a default parameter is hardly obvious documentation.
- 0x457 4y agoaxum's Response is an alias for `http::Response<UnsyncBoxBody<Bytes, Error>>`. It's not a fallback or catch-all, it's the type that axum expects to be returned by handler directly or indirectly via `IntoResponse` trait. All of that is very clear if you open : https://docs.rs/axum/latest/axum/index.html https://docs.rs/axum/latest/axum/index.html Look at `IntoResponse` trait, you will see that it's the type you need to return. The difference between `impl IntoResponse`, Some type that implements `IntoResponse` and `http::Response<UnsyncBoxBody<Bytes, Error>>` is where conversion happens: explicitly by your handler or by axum implicitly. You don't have to "explicitly convert to Bytes", you call `into_response` on whatever implements it.