Trait core::iter::DoubleEndedIterator
[−]
[src]
pub trait DoubleEndedIterator: Iterator { fn next_back(&mut self) -> Option<Self::Item>; }
An iterator able to yield elements from both ends.
Something that implements DoubleEndedIterator
has one extra capability
over something that implements Iterator
: the ability to also take
Item
s from the back, as well as the front.
It is important to note that both back and forth work on the same range, and do not cross: iteration is over when they meet in the middle.
Examples
Basic usage:
fn main() { let numbers = vec![1, 2, 3]; let mut iter = numbers.iter(); let n = iter.next(); assert_eq!(Some(&1), n); let n = iter.next_back(); assert_eq!(Some(&3), n); let n = iter.next_back(); assert_eq!(Some(&2), n); let n = iter.next(); assert_eq!(None, n); let n = iter.next_back(); assert_eq!(None, n); }let numbers = vec![1, 2, 3]; let mut iter = numbers.iter(); let n = iter.next(); assert_eq!(Some(&1), n); let n = iter.next_back(); assert_eq!(Some(&3), n); let n = iter.next_back(); assert_eq!(Some(&2), n); let n = iter.next(); assert_eq!(None, n); let n = iter.next_back(); assert_eq!(None, n);
Required Methods
fn next_back(&mut self) -> Option<Self::Item>
An iterator able to yield elements from both ends.
As this is the only method for this trait, the trait-level docs contain more details.
Examples
Basic usage:
fn main() { let numbers = vec![1, 2, 3]; let mut iter = numbers.iter(); let n = iter.next(); assert_eq!(Some(&1), n); let n = iter.next_back(); assert_eq!(Some(&3), n); let n = iter.next_back(); assert_eq!(Some(&2), n); let n = iter.next(); assert_eq!(None, n); let n = iter.next_back(); assert_eq!(None, n); }let numbers = vec![1, 2, 3]; let mut iter = numbers.iter(); let n = iter.next(); assert_eq!(Some(&1), n); let n = iter.next_back(); assert_eq!(Some(&3), n); let n = iter.next_back(); assert_eq!(Some(&2), n); let n = iter.next(); assert_eq!(None, n); let n = iter.next_back(); assert_eq!(None, n);
Implementors
impl<'a, I: DoubleEndedIterator + ?Sized> DoubleEndedIterator for &'a mut I
impl<I> DoubleEndedIterator for Rev<I> where I: DoubleEndedIterator
impl<'a, I, T: 'a> DoubleEndedIterator for Cloned<I> where I: DoubleEndedIterator<Item=&'a T>, T: Clone
impl<A, B> DoubleEndedIterator for Chain<A, B> where A: DoubleEndedIterator, B: DoubleEndedIterator<Item=A::Item>
impl<A, B> DoubleEndedIterator for Zip<A, B> where A: DoubleEndedIterator + ExactSizeIterator, B: DoubleEndedIterator + ExactSizeIterator
impl<B, I: DoubleEndedIterator, F> DoubleEndedIterator for Map<I, F> where F: FnMut(I::Item) -> B
impl<I: DoubleEndedIterator, P> DoubleEndedIterator for Filter<I, P> where P: FnMut(&I::Item) -> bool
impl<B, I: DoubleEndedIterator, F> DoubleEndedIterator for FilterMap<I, F> where F: FnMut(I::Item) -> Option<B>
impl<I> DoubleEndedIterator for Enumerate<I> where I: ExactSizeIterator + DoubleEndedIterator
impl<I: DoubleEndedIterator, U, F> DoubleEndedIterator for FlatMap<I, U, F> where F: FnMut(I::Item) -> U, U: IntoIterator, U::IntoIter: DoubleEndedIterator
impl<I> DoubleEndedIterator for Fuse<I> where I: DoubleEndedIterator
impl<I: DoubleEndedIterator, F> DoubleEndedIterator for Inspect<I, F> where F: FnMut(&I::Item)
impl<A> DoubleEndedIterator for RangeInclusive<A> where A: PartialEq + Step + One + Clone, &'a A: Add<&'a A, Output=A>, &'a A: Sub<Output=A>
impl<A: Step + One + Clone> DoubleEndedIterator for Range<A> where &'a A: Add<&'a A, Output=A>, &'a A: Sub<&'a A, Output=A>
impl<A: Clone> DoubleEndedIterator for Repeat<A>
impl<T> DoubleEndedIterator for Empty<T>
impl<T> DoubleEndedIterator for Once<T>
impl<'a, A> DoubleEndedIterator for Iter<'a, A>
impl<'a, A> DoubleEndedIterator for IterMut<'a, A>
impl<A> DoubleEndedIterator for IntoIter<A>
impl<'a, T> DoubleEndedIterator for Iter<'a, T>
impl<'a, T> DoubleEndedIterator for IterMut<'a, T>
impl<T> DoubleEndedIterator for IntoIter<T>
impl<'a, T> DoubleEndedIterator for Iter<'a, T>
impl<'a, T> DoubleEndedIterator for IterMut<'a, T>
impl<'a, T, P> DoubleEndedIterator for Split<'a, T, P> where P: FnMut(&T) -> bool
impl<'a, T, P> DoubleEndedIterator for SplitMut<'a, T, P> where P: FnMut(&T) -> bool
impl<'a, T> DoubleEndedIterator for Windows<'a, T>
impl<'a, T> DoubleEndedIterator for Chunks<'a, T>
impl<'a, T> DoubleEndedIterator for ChunksMut<'a, T>
impl<'a> DoubleEndedIterator for Chars<'a>
impl<'a> DoubleEndedIterator for CharIndices<'a>
impl<'a> DoubleEndedIterator for Bytes<'a>
impl<'a, P: Pattern<'a>> DoubleEndedIterator for Split<'a, P> where P::Searcher: DoubleEndedSearcher<'a>
impl<'a, P: Pattern<'a>> DoubleEndedIterator for RSplit<'a, P> where P::Searcher: DoubleEndedSearcher<'a>
impl<'a, P: Pattern<'a>> DoubleEndedIterator for SplitTerminator<'a, P> where P::Searcher: DoubleEndedSearcher<'a>
impl<'a, P: Pattern<'a>> DoubleEndedIterator for RSplitTerminator<'a, P> where P::Searcher: DoubleEndedSearcher<'a>
impl<'a, P: Pattern<'a>> DoubleEndedIterator for MatchIndices<'a, P> where P::Searcher: DoubleEndedSearcher<'a>
impl<'a, P: Pattern<'a>> DoubleEndedIterator for RMatchIndices<'a, P> where P::Searcher: DoubleEndedSearcher<'a>
impl<'a, P: Pattern<'a>> DoubleEndedIterator for Matches<'a, P> where P::Searcher: DoubleEndedSearcher<'a>
impl<'a, P: Pattern<'a>> DoubleEndedIterator for RMatches<'a, P> where P::Searcher: DoubleEndedSearcher<'a>
impl<'a> DoubleEndedIterator for Lines<'a>
impl<'a> DoubleEndedIterator for LinesAny<'a>