Skip to content

Commit 64c8d9b

Browse files
committed
override ExactSizeIterator::len methods
1 parent 6e3dc00 commit 64c8d9b

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/lib.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -750,9 +750,13 @@ impl<'a, K, V> DoubleEndedIterator for IterMut<'a, K, V> {
750750
}
751751
}
752752

753-
impl<'a, K, V> ExactSizeIterator for Iter<'a, K, V> {}
753+
impl<'a, K, V> ExactSizeIterator for Iter<'a, K, V> {
754+
fn len(&self) -> usize { self.remaining }
755+
}
754756

755-
impl<'a, K, V> ExactSizeIterator for IterMut<'a, K, V> {}
757+
impl<'a, K, V> ExactSizeIterator for IterMut<'a, K, V> {
758+
fn len(&self) -> usize { self.remaining }
759+
}
756760

757761

758762
pub struct Keys<'a, K: 'a, V: 'a> {
@@ -774,7 +778,9 @@ impl<'a, K, V> DoubleEndedIterator for Keys<'a, K, V> {
774778
#[inline] fn next_back(&mut self) -> Option<(&'a K)> { self.inner.next_back() }
775779
}
776780

777-
impl<'a, K, V> ExactSizeIterator for Keys<'a, K, V> {}
781+
impl<'a, K, V> ExactSizeIterator for Keys<'a, K, V> {
782+
fn len(&self) -> usize { self.inner.len() }
783+
}
778784

779785

780786
pub struct Values<'a, K: 'a, V: 'a> {
@@ -796,7 +802,9 @@ impl<'a, K, V> DoubleEndedIterator for Values<'a, K, V> {
796802
#[inline] fn next_back(&mut self) -> Option<(&'a V)> { self.inner.next_back() }
797803
}
798804

799-
impl<'a, K, V> ExactSizeIterator for Values<'a, K, V> {}
805+
impl<'a, K, V> ExactSizeIterator for Values<'a, K, V> {
806+
fn len(&self) -> usize { self.inner.len() }
807+
}
800808

801809
impl<'a, K: Hash + Eq, V, S: HashState> IntoIterator for &'a LinkedHashMap<K, V, S> {
802810
type Item = (&'a K, &'a V);

0 commit comments

Comments
 (0)