Skip to content

Commit

Permalink
Override some provided Iterator methods for header map's Keys (#667)
Browse files Browse the repository at this point in the history
The `inner` iterator is simply a `slice::Iter`, so all of these can be
done in constant time. Ideally, we would override `advance_by`, but
that's still unstable.
  • Loading branch information
LukasKalbertodt committed Jan 29, 2024
1 parent bda9320 commit 9098a29
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/header/map.rs
Expand Up @@ -2196,6 +2196,18 @@ impl<'a, T> Iterator for Keys<'a, T> {
fn size_hint(&self) -> (usize, Option<usize>) {
self.inner.size_hint()
}

fn nth(&mut self, n: usize) -> Option<Self::Item> {
self.inner.nth(n).map(|b| &b.key)
}

fn count(self) -> usize {
self.inner.count()
}

fn last(self) -> Option<Self::Item> {
self.inner.last().map(|b| &b.key)
}
}

impl<'a, T> ExactSizeIterator for Keys<'a, T> {}
Expand Down

0 comments on commit 9098a29

Please sign in to comment.