diff options
| author | Steven Allen <steven@stebalien.com> | 2016-08-13 14:42:36 -0400 |
|---|---|---|
| committer | Steven Allen <steven@stebalien.com> | 2016-08-18 12:16:29 -0400 |
| commit | de91872a3337dddf9a0d27df7bfb64f3965c81b0 (patch) | |
| tree | 5204b54ce4d67aa5eb959f741167db6cba2f2454 /src/libcore | |
| parent | 43c090ed69a624928c03ad61a29a59badf80ff7b (diff) | |
| download | rust-de91872a3337dddf9a0d27df7bfb64f3965c81b0.tar.gz rust-de91872a3337dddf9a0d27df7bfb64f3965c81b0.zip | |
Add a FusedIterator trait.
This trait can be used to avoid the overhead of a fuse wrapper when an iterator is already well-behaved. Conforming to: RFC 1581 Closes: #35602
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/char.rs | 18 | ||||
| -rw-r--r-- | src/libcore/iter/mod.rs | 130 | ||||
| -rw-r--r-- | src/libcore/iter/range.rs | 24 | ||||
| -rw-r--r-- | src/libcore/iter/sources.rs | 11 | ||||
| -rw-r--r-- | src/libcore/iter/traits.rs | 16 | ||||
| -rw-r--r-- | src/libcore/option.rs | 14 | ||||
| -rw-r--r-- | src/libcore/result.rs | 10 | ||||
| -rw-r--r-- | src/libcore/slice.rs | 25 | ||||
| -rw-r--r-- | src/libcore/str/mod.rs | 25 |
9 files changed, 262 insertions, 11 deletions
diff --git a/src/libcore/char.rs b/src/libcore/char.rs index a3440fe8aa6..98b7632a220 100644 --- a/src/libcore/char.rs +++ b/src/libcore/char.rs @@ -18,6 +18,7 @@ use prelude::v1::*; use char_private::is_printable; +use iter::FusedIterator; use mem::transmute; // UTF-8 ranges and tags for encoding characters @@ -516,6 +517,9 @@ impl ExactSizeIterator for EscapeUnicode { } } +#[unstable(feature = "fused", issue = "35602")] +impl FusedIterator for EscapeUnicode {} + /// An iterator that yields the literal escape code of a `char`. /// /// This `struct` is created by the [`escape_default()`] method on [`char`]. See @@ -616,6 +620,9 @@ impl ExactSizeIterator for EscapeDefault { } } +#[unstable(feature = "fused", issue = "35602")] +impl FusedIterator for EscapeDefault {} + /// An iterator that yields the literal escape code of a `char`. /// /// This `struct` is created by the [`escape_debug()`] method on [`char`]. See its @@ -637,6 +644,9 @@ impl Iterator for EscapeDebug { #[unstable(feature = "char_escape_debug", issue = "35068")] impl ExactSizeIterator for EscapeDebug { } +#[unstable(feature = "fused", issue = "35602")] +impl FusedIterator for EscapeDebug {} + /// An iterator over `u8` entries represending the UTF-8 encoding of a `char` /// value. /// @@ -675,6 +685,9 @@ impl Iterator for EncodeUtf8 { } } +#[unstable(feature = "fused", issue = "35602")] +impl FusedIterator for EncodeUtf8 {} + /// An iterator over `u16` entries represending the UTF-16 encoding of a `char` /// value. /// @@ -714,6 +727,8 @@ impl Iterator for EncodeUtf16 { } } +#[unstable(feature = "fused", issue = "35602")] +impl FusedIterator for EncodeUtf16 {} /// An iterator over an iterator of bytes of the characters the bytes represent /// as UTF-8 @@ -760,3 +775,6 @@ impl<I: Iterator<Item = u8>> Iterator for DecodeUtf8<I> { }) } } + +#[unstable(feature = "fused", issue = "35602")] +impl<I: FusedIterator<Item = u8>> FusedIterator for DecodeUtf8<I> {} diff --git a/src/libcore/iter/mod.rs b/src/libcore/iter/mod.rs index d2de0d46d74..cfe117c0b1d 100644 --- a/src/libcore/iter/mod.rs +++ b/src/libcore/iter/mod.rs @@ -330,6 +330,8 @@ pub use self::sources::{Once, once}; pub use self::traits::{FromIterator, IntoIterator, DoubleEndedIterator, Extend}; #[stable(feature = "rust1", since = "1.0.0")] pub use self::traits::{ExactSizeIterator, Sum, Product}; +#[unstable(feature = "fused", issue = "35602")] +pub use self::traits::FusedIterator; mod iterator; mod range; @@ -370,6 +372,10 @@ impl<I> DoubleEndedIterator for Rev<I> where I: DoubleEndedIterator { impl<I> ExactSizeIterator for Rev<I> where I: ExactSizeIterator + DoubleEndedIterator {} +#[unstable(feature = "fused", issue = "35602")] +impl<I> FusedIterator for Rev<I> + where I: FusedIterator + DoubleEndedIterator {} + /// An iterator that clones the elements of an underlying iterator. /// /// This `struct` is created by the [`cloned()`] method on [`Iterator`]. See its @@ -413,6 +419,11 @@ impl<'a, I, T: 'a> ExactSizeIterator for Cloned<I> where I: ExactSizeIterator<Item=&'a T>, T: Clone {} +#[unstable(feature = "fused", issue = "35602")] +impl<'a, I, T: 'a> FusedIterator for Cloned<I> + where I: FusedIterator<Item=&'a T>, T: Clone +{} + /// An iterator that repeats endlessly. /// /// This `struct` is created by the [`cycle()`] method on [`Iterator`]. See its @@ -451,6 +462,9 @@ impl<I> Iterator for Cycle<I> where I: Clone + Iterator { } } +#[unstable(feature = "fused", issue = "35602")] +impl<I> FusedIterator for Cycle<I> where I: Clone + Iterator {} + /// An iterator that strings two iterators together. /// /// This `struct` is created by the [`chain()`] method on [`Iterator`]. See its @@ -613,6 +627,13 @@ impl<A, B> DoubleEndedIterator for Chain<A, B> where } } +// Note: *both* must be fused to handle double-ended iterators. +#[unstable(feature = "fused", issue = "35602")] +impl<A, B> FusedIterator for Chain<A, B> + where A: FusedIterator, + B: FusedIterator<Item=A::Item>, +{} + /// An iterator that iterates two other iterators simultaneously. /// /// This `struct` is created by the [`zip()`] method on [`Iterator`]. See its @@ -823,6 +844,10 @@ unsafe impl<A, B> TrustedRandomAccess for Zip<A, B> } +#[unstable(feature = "fused", issue = "35602")] +impl<A, B> FusedIterator for Zip<A, B> + where A: FusedIterator, B: FusedIterator, {} + /// An iterator that maps the values of `iter` with `f`. /// /// This `struct` is created by the [`map()`] method on [`Iterator`]. See its @@ -919,6 +944,10 @@ impl<B, I: DoubleEndedIterator, F> DoubleEndedIterator for Map<I, F> where impl<B, I: ExactSizeIterator, F> ExactSizeIterator for Map<I, F> where F: FnMut(I::Item) -> B {} +#[unstable(feature = "fused", issue = "35602")] +impl<B, I: FusedIterator, F> FusedIterator for Map<I, F> + where F: FnMut(I::Item) -> B {} + /// An iterator that filters the elements of `iter` with `predicate`. /// /// This `struct` is created by the [`filter()`] method on [`Iterator`]. See its @@ -979,6 +1008,10 @@ impl<I: DoubleEndedIterator, P> DoubleEndedIterator for Filter<I, P> } } +#[unstable(feature = "fused", issue = "35602")] +impl<I: FusedIterator, P> FusedIterator for Filter<I, P> + where P: FnMut(&I::Item) -> bool {} + /// An iterator that uses `f` to both filter and map elements from `iter`. /// /// This `struct` is created by the [`filter_map()`] method on [`Iterator`]. See its @@ -1041,6 +1074,10 @@ impl<B, I: DoubleEndedIterator, F> DoubleEndedIterator for FilterMap<I, F> } } +#[unstable(feature = "fused", issue = "35602")] +impl<B, I: FusedIterator, F> FusedIterator for FilterMap<I, F> + where F: FnMut(I::Item) -> Option<B> {} + /// An iterator that yields the current count and the element during iteration. /// /// This `struct` is created by the [`enumerate()`] method on [`Iterator`]. See its @@ -1128,6 +1165,9 @@ unsafe impl<I> TrustedRandomAccess for Enumerate<I> } } +#[unstable(feature = "fused", issue = "35602")] +impl<I> FusedIterator for Enumerate<I> where I: FusedIterator {} + /// An iterator with a `peek()` that returns an optional reference to the next /// element. /// @@ -1195,6 +1235,9 @@ impl<I: Iterator> Iterator for Peekable<I> { #[stable(feature = "rust1", since = "1.0.0")] impl<I: ExactSizeIterator> ExactSizeIterator for Peekable<I> {} +#[unstable(feature = "fused", issue = "35602")] +impl<I: FusedIterator> FusedIterator for Peekable<I> {} + impl<I: Iterator> Peekable<I> { /// Returns a reference to the next() value without advancing the iterator. /// @@ -1296,6 +1339,10 @@ impl<I: Iterator, P> Iterator for SkipWhile<I, P> } } +#[unstable(feature = "fused", issue = "35602")] +impl<I, P> FusedIterator for SkipWhile<I, P> + where I: FusedIterator, P: FnMut(&I::Item) -> bool {} + /// An iterator that only accepts elements while `predicate` is true. /// /// This `struct` is created by the [`take_while()`] method on [`Iterator`]. See its @@ -1351,6 +1398,10 @@ impl<I: Iterator, P> Iterator for TakeWhile<I, P> } } +#[unstable(feature = "fused", issue = "35602")] +impl<I, P> FusedIterator for TakeWhile<I, P> + where I: FusedIterator, P: FnMut(&I::Item) -> bool {} + /// An iterator that skips over `n` elements of `iter`. /// /// This `struct` is created by the [`skip()`] method on [`Iterator`]. See its @@ -1442,6 +1493,9 @@ impl<I> DoubleEndedIterator for Skip<I> where I: DoubleEndedIterator + ExactSize } } +#[unstable(feature = "fused", issue = "35602")] +impl<I> FusedIterator for Skip<I> where I: FusedIterator {} + /// An iterator that only iterates over the first `n` iterations of `iter`. /// /// This `struct` is created by the [`take()`] method on [`Iterator`]. See its @@ -1503,6 +1557,8 @@ impl<I> Iterator for Take<I> where I: Iterator{ #[stable(feature = "rust1", since = "1.0.0")] impl<I> ExactSizeIterator for Take<I> where I: ExactSizeIterator {} +#[unstable(feature = "fused", issue = "35602")] +impl<I> FusedIterator for Take<I> where I: FusedIterator {} /// An iterator to maintain state while iterating another iterator. /// @@ -1549,6 +1605,10 @@ impl<B, I, St, F> Iterator for Scan<I, St, F> where } } +#[unstable(feature = "fused", issue = "35602")] +impl<B, I, St, F> FusedIterator for Scan<I, St, F> + where I: FusedIterator, F: FnMut(&mut St, I::Item) -> Option<B> {} + /// An iterator that maps each element to an iterator, and yields the elements /// of the produced iterators. /// @@ -1635,6 +1695,10 @@ impl<I: DoubleEndedIterator, U, F> DoubleEndedIterator for FlatMap<I, U, F> wher } } +#[unstable(feature = "fused", issue = "35602")] +impl<I, U, F> FusedIterator for FlatMap<I, U, F> + where I: FusedIterator, U: IntoIterator, F: FnMut(I::Item) -> U {} + /// An iterator that yields `None` forever after the underlying iterator /// yields `None` once. /// @@ -1651,12 +1715,15 @@ pub struct Fuse<I> { done: bool } +#[unstable(feature = "fused", issue = "35602")] +impl<I> FusedIterator for Fuse<I> where I: Iterator {} + #[stable(feature = "rust1", since = "1.0.0")] impl<I> Iterator for Fuse<I> where I: Iterator { type Item = <I as Iterator>::Item; #[inline] - fn next(&mut self) -> Option<<I as Iterator>::Item> { + default fn next(&mut self) -> Option<<I as Iterator>::Item> { if self.done { None } else { @@ -1667,7 +1734,7 @@ impl<I> Iterator for Fuse<I> where I: Iterator { } #[inline] - fn nth(&mut self, n: usize) -> Option<I::Item> { + default fn nth(&mut self, n: usize) -> Option<I::Item> { if self.done { None } else { @@ -1678,7 +1745,7 @@ impl<I> Iterator for Fuse<I> where I: Iterator { } #[inline] - fn last(self) -> Option<I::Item> { + default fn last(self) -> Option<I::Item> { if self.done { None } else { @@ -1687,7 +1754,7 @@ impl<I> Iterator for Fuse<I> where I: Iterator { } #[inline] - fn count(self) -> usize { + default fn count(self) -> usize { if self.done { 0 } else { @@ -1696,7 +1763,7 @@ impl<I> Iterator for Fuse<I> where I: Iterator { } #[inline] - fn size_hint(&self) -> (usize, Option<usize>) { + default fn size_hint(&self) -> (usize, Option<usize>) { if self.done { (0, Some(0)) } else { @@ -1708,7 +1775,7 @@ impl<I> Iterator for Fuse<I> where I: Iterator { #[stable(feature = "rust1", since = "1.0.0")] impl<I> DoubleEndedIterator for Fuse<I> where I: DoubleEndedIterator { #[inline] - fn next_back(&mut self) -> Option<<I as Iterator>::Item> { + default fn next_back(&mut self) -> Option<<I as Iterator>::Item> { if self.done { None } else { @@ -1719,6 +1786,53 @@ impl<I> DoubleEndedIterator for Fuse<I> where I: DoubleEndedIterator { } } +unsafe impl<I> TrustedRandomAccess for Fuse<I> + where I: TrustedRandomAccess, +{ + unsafe fn get_unchecked(&mut self, i: usize) -> I::Item { + self.iter.get_unchecked(i) + } +} + +#[unstable(feature = "fused", issue = "35602")] +impl<I> Iterator for Fuse<I> where I: FusedIterator { + #[inline] + fn next(&mut self) -> Option<<I as Iterator>::Item> { + self.iter.next() + } + + #[inline] + fn nth(&mut self, n: usize) -> Option<I::Item> { + self.iter.nth(n) + } + + #[inline] + fn last(self) -> Option<I::Item> { + self.iter.last() + } + + #[inline] + fn count(self) -> usize { + self.iter.count() + } + + #[inline] + fn size_hint(&self) -> (usize, Option<usize>) { + self.iter.size_hint() + } +} + +#[unstable(feature = "fused", reason = "recently added", issue = "35602")] +impl<I> DoubleEndedIterator for Fuse<I> + where I: DoubleEndedIterator + FusedIterator +{ + #[inline] + fn next_back(&mut self) -> Option<<I as Iterator>::Item> { + self.iter.next_back() + } +} + + #[stable(feature = "rust1", since = "1.0.0")] impl<I> ExactSizeIterator for Fuse<I> where I: ExactSizeIterator {} @@ -1788,3 +1902,7 @@ impl<I: DoubleEndedIterator, F> DoubleEndedIterator for Inspect<I, F> #[stable(feature = "rust1", since = "1.0.0")] impl<I: ExactSizeIterator, F> ExactSizeIterator for Inspect<I, F> where F: FnMut(&I::Item) {} + +#[unstable(feature = "fused", issue = "35602")] +impl<I: FusedIterator, F> FusedIterator for Inspect<I, F> + where F: FnMut(&I::Item) {} diff --git a/src/libcore/iter/range.rs b/src/libcore/iter/range.rs index 079dfe2a81f..48816bf66bb 100644 --- a/src/libcore/iter/range.rs +++ b/src/libcore/iter/range.rs @@ -16,7 +16,7 @@ use option::Option::{self, Some, None}; use marker::Sized; use usize; -use super::{DoubleEndedIterator, ExactSizeIterator, Iterator}; +use super::{DoubleEndedIterator, ExactSizeIterator, Iterator, FusedIterator}; /// Objects that can be stepped over in both directions. /// @@ -364,6 +364,10 @@ impl<A> Iterator for StepBy<A, ops::RangeFrom<A>> where } } +#[unstable(feature = "fused", issue = "35602")] +impl<A> FusedIterator for StepBy<A, ops::RangeFrom<A>> + where A: Clone, for<'a> &'a A: Add<&'a A, Output = A> {} + #[stable(feature = "rust1", since = "1.0.0")] impl<A: Step + Clone> Iterator for StepBy<A, ops::Range<A>> { type Item = A; @@ -401,6 +405,9 @@ impl<A: Step + Clone> Iterator for StepBy<A, ops::Range<A>> { } } +#[unstable(feature = "fused", issue = "35602")] +impl<A: Step + Clone> FusedIterator for StepBy<A, ops::Range<A>> {} + #[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")] @@ -468,6 +475,9 @@ impl<A: Step + Clone> Iterator for StepBy<A, ops::RangeInclusive<A>> { } } +#[unstable(feature = "fused", issue = "35602")] +impl<A: Step + Clone> FusedIterator for StepBy<A, ops::RangeInclusive<A>> {} + macro_rules! range_exact_iter_impl { ($($t:ty)*) => ($( #[stable(feature = "rust1", since = "1.0.0")] @@ -526,6 +536,10 @@ impl<A: Step + Clone> DoubleEndedIterator for ops::Range<A> where } } +#[unstable(feature = "fused", issue = "35602")] +impl<A> FusedIterator for ops::Range<A> + where A: Step, for<'a> &'a A: Add<&'a A, Output = A> {} + #[stable(feature = "rust1", since = "1.0.0")] impl<A: Step> Iterator for ops::RangeFrom<A> where for<'a> &'a A: Add<&'a A, Output = A> @@ -540,6 +554,10 @@ impl<A: Step> Iterator for ops::RangeFrom<A> where } } +#[unstable(feature = "fused", issue = "35602")] +impl<A> FusedIterator for ops::RangeFrom<A> + where A: Step, for<'a> &'a A: Add<&'a A, Output = A> {} + #[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")] impl<A: Step> Iterator for ops::RangeInclusive<A> where for<'a> &'a A: Add<&'a A, Output = A> @@ -638,3 +656,7 @@ impl<A: Step> DoubleEndedIterator for ops::RangeInclusive<A> where n } } + +#[unstable(feature = "fused", issue = "35602")] +impl<A> FusedIterator for ops::RangeInclusive<A> + where A: Step, for<'a> &'a A: Add<&'a A, Output = A> {} diff --git a/src/libcore/iter/sources.rs b/src/libcore/iter/sources.rs index ecd4a78b9e7..a2a019a07dc 100644 --- a/src/libcore/iter/sources.rs +++ b/src/libcore/iter/sources.rs @@ -15,7 +15,7 @@ use marker; use option::Option::{self, Some, None}; use usize; -use super::{DoubleEndedIterator, IntoIterator, Iterator, ExactSizeIterator}; +use super::{DoubleEndedIterator, IntoIterator, Iterator, ExactSizeIterator, FusedIterator}; /// An iterator that repeats an element endlessly. /// @@ -44,6 +44,9 @@ impl<A: Clone> DoubleEndedIterator for Repeat<A> { fn next_back(&mut self) -> Option<A> { Some(self.element.clone()) } } +#[unstable(feature = "fused", issue = "35602")] +impl<A: Clone> FusedIterator for Repeat<A> {} + /// Creates a new iterator that endlessly repeats a single element. /// /// The `repeat()` function repeats a single value over and over and over and @@ -138,6 +141,9 @@ impl<T> ExactSizeIterator for Empty<T> { } } +#[unstable(feature = "fused", issue = "35602")] +impl<T> FusedIterator for Empty<T> {} + // not #[derive] because that adds a Clone bound on T, // which isn't necessary. #[stable(feature = "iter_empty", since = "1.2.0")] @@ -213,6 +219,9 @@ impl<T> ExactSizeIterator for Once<T> { } } +#[unstable(feature = "fused", issue = "35602")] +impl<T> FusedIterator for Once<T> {} + /// Creates an iterator that yields an element exactly once. /// /// This is commonly used to adapt a single value into a [`chain()`] of other diff --git a/src/libcore/iter/traits.rs b/src/libcore/iter/traits.rs index 4cbabe3f5ed..0b6ab5a4bbb 100644 --- a/src/libcore/iter/traits.rs +++ b/src/libcore/iter/traits.rs @@ -658,3 +658,19 @@ macro_rules! float_sum_product { integer_sum_product! { i8 i16 i32 i64 isize u8 u16 u32 u64 usize } float_sum_product! { f32 f64 } + +/// An iterator that always continues to yield `None` when exhausted. +/// +/// Calling next on a fused iterator that has returned `None` once is guaranteed +/// to return `None` again. This trait is should be implemented by all iterators +/// that behave this way because it allows for some significant optimizations. +/// +/// Note: In general, you should not use `FusedIterator` in generic bounds if +/// you need a fused iterator. Instead, you should just call `Iterator::fused()` +/// on the iterator. If the iterator is already fused, the additional `Fuse` +/// wrapper will be a no-op with no performance penalty. +#[unstable(feature = "fused", issue = "35602")] +pub trait FusedIterator: Iterator {} + +#[unstable(feature = "fused", issue = "35602")] +impl<'a, I: FusedIterator + ?Sized> FusedIterator for &'a mut I {} diff --git a/src/libcore/option.rs b/src/libcore/option.rs index fe508adb713..51bbad085fb 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -144,8 +144,8 @@ use self::Option::*; use clone::Clone; use convert::From; use default::Default; -use iter::ExactSizeIterator; -use iter::{Iterator, DoubleEndedIterator, FromIterator, IntoIterator}; +use iter::{Iterator, FromIterator, IntoIterator, ExactSizeIterator, DoubleEndedIterator}; +use iter::FusedIterator; use mem; use ops::FnOnce; use result::Result::{Ok, Err}; @@ -796,6 +796,7 @@ impl<A> DoubleEndedIterator for Item<A> { } impl<A> ExactSizeIterator for Item<A> {} +impl<A> FusedIterator for Item<A> {} /// An iterator over a reference of the contained item in an Option. #[stable(feature = "rust1", since = "1.0.0")] @@ -821,6 +822,9 @@ impl<'a, A> DoubleEndedIterator for Iter<'a, A> { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, A> ExactSizeIterator for Iter<'a, A> {} +#[unstable(feature = "fused", issue = "35602")] +impl<'a, A> FusedIterator for Iter<'a, A> {} + #[stable(feature = "rust1", since = "1.0.0")] impl<'a, A> Clone for Iter<'a, A> { fn clone(&self) -> Iter<'a, A> { @@ -852,6 +856,9 @@ impl<'a, A> DoubleEndedIterator for IterMut<'a, A> { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, A> ExactSizeIterator for IterMut<'a, A> {} +#[unstable(feature = "fused", issue = "35602")] +impl<'a, A> FusedIterator for IterMut<'a, A> {} + /// An iterator over the item contained inside an Option. #[derive(Clone, Debug)] #[stable(feature = "rust1", since = "1.0.0")] @@ -876,6 +883,9 @@ impl<A> DoubleEndedIterator for IntoIter<A> { #[stable(feature = "rust1", since = "1.0.0")] impl<A> ExactSizeIterator for IntoIter<A> {} +#[unstable(feature = "fused", issue = "35602")] +impl<A> FusedIterator for IntoIter<A> {} + ///////////////////////////////////////////////////////////////////////////// // FromIterator ///////////////////////////////////////////////////////////////////////////// diff --git a/src/libcore/result.rs b/src/libcore/result.rs index c7ca70fc162..718fdf865a9 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -241,6 +241,7 @@ use self::Result::{Ok, Err}; use clone::Clone; use fmt; use iter::{Iterator, DoubleEndedIterator, FromIterator, ExactSizeIterator, IntoIterator}; +use iter::FusedIterator; use ops::FnOnce; use option::Option::{self, None, Some}; @@ -869,6 +870,9 @@ impl<'a, T> DoubleEndedIterator for Iter<'a, T> { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> ExactSizeIterator for Iter<'a, T> {} +#[unstable(feature = "fused", issue = "35602")] +impl<'a, T> FusedIterator for Iter<'a, T> {} + #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> Clone for Iter<'a, T> { fn clone(&self) -> Iter<'a, T> { Iter { inner: self.inner } } @@ -901,6 +905,9 @@ impl<'a, T> DoubleEndedIterator for IterMut<'a, T> { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> ExactSizeIterator for IterMut<'a, T> {} +#[unstable(feature = "fused", issue = "35602")] +impl<'a, T> FusedIterator for IterMut<'a, T> {} + /// An iterator over the value in a `Ok` variant of a `Result`. #[derive(Debug)] #[stable(feature = "rust1", since = "1.0.0")] @@ -928,6 +935,9 @@ impl<T> DoubleEndedIterator for IntoIter<T> { #[stable(feature = "rust1", since = "1.0.0")] impl<T> ExactSizeIterator for IntoIter<T> {} +#[unstable(feature = "fused", issue = "35602")] +impl<T> FusedIterator for IntoIter<T> {} + ///////////////////////////////////////////////////////////////////////////// // FromIterator ///////////////////////////////////////////////////////////////////////////// diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 3a820a14f12..603f55a6e10 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -992,6 +992,9 @@ iterator!{struct Iter -> *const T, &'a T} #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> ExactSizeIterator for Iter<'a, T> {} +#[unstable(feature = "fused", issue = "35602")] +impl<'a, T> FusedIterator for Iter<'a, T> {} + #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> Clone for Iter<'a, T> { fn clone(&self) -> Iter<'a, T> { Iter { ptr: self.ptr, end: self.end, _marker: self._marker } } @@ -1110,6 +1113,9 @@ iterator!{struct IterMut -> *mut T, &'a mut T} #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> ExactSizeIterator for IterMut<'a, T> {} +#[unstable(feature = "fused", issue = "35602")] +impl<'a, T> FusedIterator for IterMut<'a, T> {} + /// An internal abstraction over the splitting iterators, so that /// splitn, splitn_mut etc can be implemented once. #[doc(hidden)] @@ -1202,6 +1208,9 @@ impl<'a, T, P> SplitIter for Split<'a, T, P> where P: FnMut(&T) -> bool { } } +#[unstable(feature = "fused", issue = "35602")] +impl<'a, T, P> FusedIterator for Split<'a, T, P> where P: FnMut(&T) -> bool {} + /// An iterator over the subslices of the vector which are separated /// by elements that match `pred`. #[stable(feature = "rust1", since = "1.0.0")] @@ -1292,6 +1301,9 @@ impl<'a, T, P> DoubleEndedIterator for SplitMut<'a, T, P> where } } +#[unstable(feature = "fused", issue = "35602")] +impl<'a, T, P> FusedIterator for SplitMut<'a, T, P> where P: FnMut(&T) -> bool {} + /// An private iterator over subslices separated by elements that /// match a predicate function, splitting at most a fixed number of /// times. @@ -1408,6 +1420,10 @@ macro_rules! forward_iterator { self.inner.size_hint() } } + + #[unstable(feature = "fused", issue = "35602")] + impl<'a, $elem, P> FusedIterator for $name<'a, $elem, P> + where P: FnMut(&T) -> bool {} } } @@ -1506,6 +1522,9 @@ impl<'a, T> DoubleEndedIterator for Windows<'a, T> { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> ExactSizeIterator for Windows<'a, T> {} +#[unstable(feature = "fused", issue = "35602")] +impl<'a, T> FusedIterator for Windows<'a, T> {} + /// An iterator over a slice in (non-overlapping) chunks (`size` elements at a /// time). /// @@ -1609,6 +1628,9 @@ impl<'a, T> DoubleEndedIterator for Chunks<'a, T> { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> ExactSizeIterator for Chunks<'a, T> {} +#[unstable(feature = "fused", issue = "35602")] +impl<'a, T> FusedIterator for Chunks<'a, T> {} + /// An iterator over a slice in (non-overlapping) mutable chunks (`size` /// elements at a time). When the slice len is not evenly divided by the chunk /// size, the last slice of the iteration will be the remainder. @@ -1704,6 +1726,9 @@ impl<'a, T> DoubleEndedIterator for ChunksMut<'a, T> { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> ExactSizeIterator for ChunksMut<'a, T> {} +#[unstable(feature = "fused", issue = "35602")] +impl<'a, T> FusedIterator for ChunksMut<'a, T> {} + // // Free functions // diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index fdcadd43a0f..e18aa07b75d 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -23,7 +23,7 @@ use convert::AsRef; use default::Default; use fmt; use iter::ExactSizeIterator; -use iter::{Map, Cloned, Iterator, DoubleEndedIterator}; +use iter::{Map, Cloned, Iterator, DoubleEndedIterator, FusedIterator}; use marker::Sized; use mem; use ops::{Fn, FnMut, FnOnce}; @@ -454,6 +454,9 @@ impl<'a> DoubleEndedIterator for Chars<'a> { } } +#[unstable(feature = "fused", issue = "35602")] +impl<'a> FusedIterator for Chars<'a> {} + impl<'a> Chars<'a> { /// View the underlying data as a subslice of the original data. /// @@ -525,6 +528,9 @@ impl<'a> DoubleEndedIterator for CharIndices<'a> { } } +#[unstable(feature = "fused", issue = "35602")] +impl<'a> FusedIterator for CharIndices<'a> {} + impl<'a> CharIndices<'a> { /// View the underlying data as a subslice of the original data. /// @@ -593,6 +599,9 @@ impl<'a> ExactSizeIterator for Bytes<'a> { } } +#[unstable(feature = "fused", issue = "35602")] +impl<'a> FusedIterator for Bytes<'a> {} + /// This macro generates a Clone impl for string pattern API /// wrapper types of the form X<'a, P> macro_rules! derive_pattern_clone { @@ -739,6 +748,13 @@ macro_rules! generate_pattern_iterators { } } + #[unstable(feature = "fused", issue = "35602")] + impl<'a, P: Pattern<'a>> FusedIterator for $forward_iterator<'a, P> {} + + #[unstable(feature = "fused", issue = "35602")] + impl<'a, P: Pattern<'a>> FusedIterator for $reverse_iterator<'a, P> + where P::Searcher: ReverseSearcher<'a> {} + generate_pattern_iterators!($($t)* with $(#[$common_stability_attribute])*, $forward_iterator, $reverse_iterator, $iterty); @@ -1088,6 +1104,9 @@ impl<'a> DoubleEndedIterator for Lines<'a> { } } +#[unstable(feature = "fused", issue = "35602")] +impl<'a> FusedIterator for Lines<'a> {} + /// Created with the method [`lines_any()`]. /// /// [`lines_any()`]: ../../std/primitive.str.html#method.lines_any @@ -1151,6 +1170,10 @@ impl<'a> DoubleEndedIterator for LinesAny<'a> { } } +#[unstable(feature = "fused", issue = "35602")] +#[allow(deprecated)] +impl<'a> FusedIterator for LinesAny<'a> {} + /* Section: Comparing strings */ |
