diff options
| author | Phlosioneer <mattmdrr2@gmail.com> | 2018-03-20 05:33:59 -0400 |
|---|---|---|
| committer | Phlosioneer <mattmdrr2@gmail.com> | 2018-03-20 05:33:59 -0400 |
| commit | 619003d1d414167630331efffe83702f74413be6 (patch) | |
| tree | c986c64f37ab88feda2f7df926261e133d385aad /src/libcore | |
| parent | 6bfa7d02d6713acd15ead20c199b808e85031f9e (diff) | |
Implement some trivial size_hints for various iterators
This also implements ExactSizeIterator where applicable. Addresses most of the Iterator traits mentioned in #23708.
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/char.rs | 5 | ||||
| -rw-r--r-- | src/libcore/iter/traits.rs | 4 | ||||
| -rw-r--r-- | src/libcore/option.rs | 5 |
3 files changed, 14 insertions, 0 deletions
diff --git a/src/libcore/char.rs b/src/libcore/char.rs index 1638f9710f5..2f56238a463 100644 --- a/src/libcore/char.rs +++ b/src/libcore/char.rs @@ -902,6 +902,11 @@ impl<I: Iterator<Item = u8>> Iterator for DecodeUtf8<I> { } }) } + + #[inline] + fn size_hint(&self) -> (usize, Option<usize>) { + self.0.size_hint() + } } #[unstable(feature = "decode_utf8", issue = "33906")] diff --git a/src/libcore/iter/traits.rs b/src/libcore/iter/traits.rs index 0267fcd3754..5e4622f804a 100644 --- a/src/libcore/iter/traits.rs +++ b/src/libcore/iter/traits.rs @@ -901,6 +901,10 @@ impl<I, T, E> Iterator for ResultShunt<I, E> None => None, } } + + fn size_hint(&self) -> (usize, Option<usize>) { + self.iter.size_hint() + } } #[stable(feature = "iter_arith_traits_result", since="1.16.0")] diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 570f745f833..1ca69f3f503 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -1188,6 +1188,11 @@ impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> { None => None, } } + + #[inline] + fn size_hint(&self) -> (usize, Option<usize>) { + self.iter.size_hint() + } } let mut adapter = Adapter { iter: iter.into_iter(), found_none: false }; |
