diff options
| author | sinkuu <sinkuupump@gmail.com> | 2015-05-02 14:01:38 +0900 |
|---|---|---|
| committer | sinkuu <sinkuupump@gmail.com> | 2015-05-02 17:05:43 +0900 |
| commit | 5d8431c20387531d7dcbb6ad3841d15fe41b3c09 (patch) | |
| tree | 07bc1d9b001d02ad570f826fe25cec020610cd05 | |
| parent | b858b7f4ced2acaabcf1d0f59abd4a0c4a62ded3 (diff) | |
| download | rust-5d8431c20387531d7dcbb6ad3841d15fe41b3c09.tar.gz rust-5d8431c20387531d7dcbb6ad3841d15fe41b3c09.zip | |
Override Iterator::count method in vec::IntoIter
| -rw-r--r-- | src/libcollections/vec.rs | 5 | ||||
| -rw-r--r-- | src/libcollectionstest/vec.rs | 5 |
2 files changed, 10 insertions, 0 deletions
diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 33de6b79736..935648099a7 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -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")] diff --git a/src/libcollectionstest/vec.rs b/src/libcollectionstest/vec.rs index 8a8da0d9faa..ac9cf198d67 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(|| { |
