From 5d8431c20387531d7dcbb6ad3841d15fe41b3c09 Mon Sep 17 00:00:00 2001 From: sinkuu Date: Sat, 2 May 2015 14:01:38 +0900 Subject: [PATCH] Override Iterator::count method in vec::IntoIter --- src/libcollections/vec.rs | 5 +++++ src/libcollectionstest/vec.rs | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 33de6b7973672..935648099a7d3 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1777,6 +1777,11 @@ impl Iterator for IntoIter { 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")] diff --git a/src/libcollectionstest/vec.rs b/src/libcollectionstest/vec.rs index 8a8da0d9faaea..ac9cf198d6732 100644 --- a/src/libcollectionstest/vec.rs +++ b/src/libcollectionstest/vec.rs @@ -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(|| {