Skip to content

Commit 2bc365e

Browse files
committed
Implement ExactSizeIterator on Drain and IntoIter
1 parent d97f391 commit 2bc365e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ impl<'a, T: 'a> Iterator for Drain<'a,T> {
7171
}
7272
}
7373
}
74+
75+
#[inline]
76+
fn size_hint(&self) -> (usize, Option<usize>) {
77+
self.iter.size_hint()
78+
}
7479
}
7580

7681
impl<'a, T: 'a> DoubleEndedIterator for Drain<'a, T> {
@@ -87,6 +92,8 @@ impl<'a, T: 'a> DoubleEndedIterator for Drain<'a, T> {
8792
}
8893
}
8994

95+
impl<'a, T> ExactSizeIterator for Drain<'a, T> { }
96+
9097
impl<'a, T: 'a> Drop for Drain<'a,T> {
9198
fn drop(&mut self) {
9299
// Destroy the remaining elements.
@@ -524,6 +531,12 @@ impl<A: Array> Iterator for IntoIter<A> {
524531
}
525532
}
526533
}
534+
535+
#[inline]
536+
fn size_hint(&self) -> (usize, Option<usize>) {
537+
let size = self.end - self.current;
538+
(size, Some(size))
539+
}
527540
}
528541

529542
impl<A: Array> DoubleEndedIterator for IntoIter<A> {
@@ -541,6 +554,8 @@ impl<A: Array> DoubleEndedIterator for IntoIter<A> {
541554
}
542555
}
543556

557+
impl<A: Array> ExactSizeIterator for IntoIter<A> { }
558+
544559
impl<A: Array> IntoIterator for SmallVec<A> {
545560
type IntoIter = IntoIter<A>;
546561
type Item = A::Item;

0 commit comments

Comments
 (0)