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

Generalize AppendHeaders to accept any impl IntoIterator #1495

Merged
merged 2 commits into from
Oct 20, 2022
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
2 changes: 2 additions & 0 deletions axum-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- **added:** Add `DefaultBodyLimit::max` for changing the default body limit ([#1397])
- **added:** Add `Error::into_inner` for converting `Error` to `BoxError` without allocating ([#1476])
- **breaking:** `AppendHeaders` now works on any `impl IntoIterator` ([#1495])

[#1397]: https://github.com/tokio-rs/axum/pull/1397
[#1476]: https://github.com/tokio-rs/axum/pull/1476
[#1495]: https://github.com/tokio-rs/axum/pull/1495

# 0.3.0-rc.2 (10. September, 2022)

Expand Down
8 changes: 5 additions & 3 deletions axum-core/src/response/append_headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ use std::fmt;
/// }
/// ```
#[derive(Debug)]
pub struct AppendHeaders<K, V, const N: usize>(pub [(K, V); N]);
pub struct AppendHeaders<I>(pub I);

impl<K, V, const N: usize> IntoResponse for AppendHeaders<K, V, N>
impl<I, K, V> IntoResponse for AppendHeaders<I>
where
I: IntoIterator<Item = (K, V)>,
K: TryInto<HeaderName>,
K::Error: fmt::Display,
V: TryInto<HeaderValue>,
Expand All @@ -44,8 +45,9 @@ where
}
}

impl<K, V, const N: usize> IntoResponseParts for AppendHeaders<K, V, N>
impl<I, K, V> IntoResponseParts for AppendHeaders<I>
where
I: IntoIterator<Item = (K, V)>,
K: TryInto<HeaderName>,
K::Error: fmt::Display,
V: TryInto<HeaderValue>,
Expand Down