hyperium / http

Rust HTTP types
Apache License 2.0
1.12k stars 283 forks source link

[Breaking Change] Headers' IntoIterator should return a tuple (HeaderName, T) rather than T #585

Closed ConsoleTVs closed 1 year ago

ConsoleTVs commented 1 year ago

Right now, the implementation for the trait IntoIterator for HeaderMap is:

impl<T> IntoIterator for HeaderMap<T> {
    type Item = (Option<HeaderName>, T);
    type IntoIter = IntoIter<T>;

    fn into_iter(self) -> IntoIter<T> { ... }
}

This does not allow to iterate over (header, value) pairs and is missleading since Both Item and IntoIter types are unused.

I propose to change this implementation to something along those lines:

impl<T> IntoIterator for HeaderMap<T> {
    type Item = (HeaderName, T);
    type IntoIter = IntoIter<Self::Item>;

    fn into_iter(self) -> Self::IntoIter { ... }
}

With the changes to this, iterations should be way easier now:

for (header, value) in headers {
  // header: HeaderName
  // value: T
}