Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement IntoResponse for boxed slices #2035

Merged
merged 3 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions axum-core/src/response/into_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ impl IntoResponse for String {
}
}

impl IntoResponse for Box<str> {
fn into_response(self) -> Response {
String::from(self).into_response()
}
}

impl IntoResponse for Cow<'static, str> {
fn into_response(self) -> Response {
let mut res = Body::from(self).into_response();
Expand Down Expand Up @@ -315,6 +321,12 @@ impl IntoResponse for Vec<u8> {
}
}

impl IntoResponse for Box<[u8]> {
fn into_response(self) -> Response {
Vec::from(self).into_response()
}
}

impl IntoResponse for Cow<'static, [u8]> {
fn into_response(self) -> Response {
let mut res = Body::from(self).into_response();
Expand Down
1 change: 1 addition & 0 deletions axum/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **breaking:** Only inherit fallbacks for routers nested with `Router::nest`.
Routers nested with `Router::nest_service` will no longer inherit fallbacks ([#1956])
- **fixed:** Don't remove the `Sec-WebSocket-Key` header in `WebSocketUpgrade` ([#1972])
- **added:** Implement `IntoResponse` for `Box<str>` and `Box<[u8]>` ([#2035])

[#1664]: https:/tokio-rs/axum/pull/1664
[#1751]: https:/tokio-rs/axum/pull/1751
Expand Down