trait
DoubleEndedIterator — consume from either end
A double-ended iterator supports front and back consumption from one remaining sequence. The two cursors share the remaining items and must not cross. Expected stdout (not executed): Some("first") Some("last") Some("middle") Common mistake: Assuming next_back starts a separate traversal.
Formal Syntax & Structure
rust syntaxrust
trait DoubleEndedIterator: Iterator { fn next_back(&mut self) -> Option<Self::Item>; /* provided methods */ }Working Example
Example Snippetrust
fn main() { let mut queue = ["first", "middle", "last"].into_iter(); println!("{:?} {:?} {:?}", queue.next(), queue.next_back(), queue.next());}