Override Iterator::count method in vec::IntoIter

This commit is contained in:
sinkuu 2015-05-02 14:01:38 +09:00
parent b858b7f4ce
commit 5d8431c203
2 changed files with 10 additions and 0 deletions

View File

@ -1777,6 +1777,11 @@ impl<T> Iterator for IntoIter<T> {
let exact = diff / (if size == 0 {1} else {size});
(exact, Some(exact))
}
#[inline]
fn count(self) -> usize {
self.size_hint().0
}
}
#[stable(feature = "rust1", since = "1.0.0")]

View File

@ -542,6 +542,11 @@ fn test_split_off() {
assert_eq!(vec2, [5, 6]);
}
#[test]
fn test_into_iter_count() {
assert_eq!(vec![1, 2, 3].into_iter().count(), 3);
}
#[bench]
fn bench_new(b: &mut Bencher) {
b.iter(|| {