Struct collections::linked_list::IterMut
[−]
[src]
pub struct IterMut<'a, T: 'a> { // some fields omitted }1.0.0
An iterator over mutable references to the items of a LinkedList
.
Methods
impl<'a, A> IterMut<'a, A>
fn insert_next(&mut self, elt: A)
Inserts elt
just after the element most recently returned by .next()
.
The inserted element does not appear in the iteration.
Examples
#![feature(linked_list_extras)] extern crate collections; fn main() { use std::collections::LinkedList; let mut list: LinkedList<_> = vec![1, 3, 4].into_iter().collect(); { let mut it = list.iter_mut(); assert_eq!(it.next().unwrap(), &1); // insert `2` after `1` it.insert_next(2); } { let vec: Vec<_> = list.into_iter().collect(); assert_eq!(vec, [1, 2, 3, 4]); } }#![feature(linked_list_extras)] use std::collections::LinkedList; let mut list: LinkedList<_> = vec![1, 3, 4].into_iter().collect(); { let mut it = list.iter_mut(); assert_eq!(it.next().unwrap(), &1); // insert `2` after `1` it.insert_next(2); } { let vec: Vec<_> = list.into_iter().collect(); assert_eq!(vec, [1, 2, 3, 4]); }
fn peek_next(&mut self) -> Option<&mut A>
Provides a reference to the next element, without changing the iterator.
Examples
#![feature(linked_list_extras)] extern crate collections; fn main() { use std::collections::LinkedList; let mut list: LinkedList<_> = vec![1, 2, 3].into_iter().collect(); let mut it = list.iter_mut(); assert_eq!(it.next().unwrap(), &1); assert_eq!(it.peek_next().unwrap(), &2); // We just peeked at 2, so it was not consumed from the iterator. assert_eq!(it.next().unwrap(), &2); }#![feature(linked_list_extras)] use std::collections::LinkedList; let mut list: LinkedList<_> = vec![1, 2, 3].into_iter().collect(); let mut it = list.iter_mut(); assert_eq!(it.next().unwrap(), &1); assert_eq!(it.peek_next().unwrap(), &2); // We just peeked at 2, so it was not consumed from the iterator. assert_eq!(it.next().unwrap(), &2);