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
This commit is contained in:
Steven Allen
2016-08-13 14:42:36 -04:00
parent 43c090ed69
commit de91872a33
29 changed files with 437 additions and 24 deletions

View File

@@ -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