Skip to content

Commit

Permalink
Call through to inner size_hint
Browse files Browse the repository at this point in the history
Currently our `size_hint` methods are calling `len` (from
`ExactSizeIterator`) which is incorrect. We should in fact call
`size_hint` on the inner iterator.
  • Loading branch information
tcharding committed Jun 29, 2023
1 parent 0336da0 commit 2a12d2e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/primitives/hrp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ pub struct ByteIter<'b> {
impl<'b> Iterator for ByteIter<'b> {
type Item = u8;
fn next(&mut self) -> Option<u8> { self.iter.next().copied() }
fn size_hint(&self) -> (usize, Option<usize>) { (self.len(), Some(self.len())) }
fn size_hint(&self) -> (usize, Option<usize>) { self.iter.size_hint() }
}

impl<'b> ExactSizeIterator for ByteIter<'b> {
Expand All @@ -230,7 +230,7 @@ pub struct CharIter<'b> {
impl<'b> Iterator for CharIter<'b> {
type Item = char;
fn next(&mut self) -> Option<char> { self.iter.next().map(Into::into) }
fn size_hint(&self) -> (usize, Option<usize>) { (self.len(), Some(self.len())) }
fn size_hint(&self) -> (usize, Option<usize>) { self.iter.size_hint() }
}

impl<'b> ExactSizeIterator for CharIter<'b> {
Expand All @@ -253,7 +253,7 @@ impl<'b> Iterator for LowercaseByteIter<'b> {
fn next(&mut self) -> Option<u8> {
self.iter.next().map(|b| if is_ascii_uppercase(b) { b | 32 } else { b })
}
fn size_hint(&self) -> (usize, Option<usize>) { (self.len(), Some(self.len())) }
fn size_hint(&self) -> (usize, Option<usize>) { self.iter.size_hint() }
}

impl<'b> ExactSizeIterator for LowercaseByteIter<'b> {
Expand All @@ -276,7 +276,7 @@ pub struct LowercaseCharIter<'b> {
impl<'b> Iterator for LowercaseCharIter<'b> {
type Item = char;
fn next(&mut self) -> Option<char> { self.iter.next().map(Into::into) }
fn size_hint(&self) -> (usize, Option<usize>) { (self.len(), Some(self.len())) }
fn size_hint(&self) -> (usize, Option<usize>) { self.iter.size_hint() }
}

impl<'b> ExactSizeIterator for LowercaseCharIter<'b> {
Expand Down

0 comments on commit 2a12d2e

Please sign in to comment.