Implement ExactSizeIterator on Drain and IntoIter

This commit is contained in:
Markus
2016-07-31 21:35:53 +02:00
parent d97f391cf3
commit 2bc365eab3
+15
View File
@@ -71,6 +71,11 @@ impl<'a, T: 'a> Iterator for Drain<'a,T> {
}
}
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}
}
impl<'a, T: 'a> DoubleEndedIterator for Drain<'a, T> {
@@ -87,6 +92,8 @@ impl<'a, T: 'a> DoubleEndedIterator for Drain<'a, T> {
}
}
impl<'a, T> ExactSizeIterator for Drain<'a, T> { }
impl<'a, T: 'a> Drop for Drain<'a,T> {
fn drop(&mut self) {
// Destroy the remaining elements.
@@ -524,6 +531,12 @@ impl<A: Array> Iterator for IntoIter<A> {
}
}
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
let size = self.end - self.current;
(size, Some(size))
}
}
impl<A: Array> DoubleEndedIterator for IntoIter<A> {
@@ -541,6 +554,8 @@ impl<A: Array> DoubleEndedIterator for IntoIter<A> {
}
}
impl<A: Array> ExactSizeIterator for IntoIter<A> { }
impl<A: Array> IntoIterator for SmallVec<A> {
type IntoIter = IntoIter<A>;
type Item = A::Item;