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