Implement size_hint for the hashmap iterators

This commit is contained in:
Gwilym Kuiper 2022-10-02 18:44:48 +01:00
parent 416f238062
commit 2d23f0a36c

View file

@ -351,6 +351,10 @@ impl<'a, K, V, ALLOCATOR: ClonableAllocator> Iterator for Iter<'a, K, V, ALLOCAT
} }
} }
} }
fn size_hint(&self) -> (usize, Option<usize>) {
(self.map.len(), Some(self.map.len()))
}
} }
impl<'a, K, V, ALLOCATOR: ClonableAllocator> IntoIterator for &'a HashMap<K, V, ALLOCATOR> { impl<'a, K, V, ALLOCATOR: ClonableAllocator> IntoIterator for &'a HashMap<K, V, ALLOCATOR> {
@ -388,6 +392,10 @@ impl<K, V, ALLOCATOR: ClonableAllocator> Iterator for IterOwned<K, V, ALLOCATOR>
} }
} }
} }
fn size_hint(&self) -> (usize, Option<usize>) {
(self.map.len(), Some(self.map.len()))
}
} }
/// An iterator over entries of a [`HashMap`] /// An iterator over entries of a [`HashMap`]