std-method
LinkedList::iter_mut
Traverse the nodes in sequence order and borrow each stored value mutably. Modify values without changing the links or length. Expected stdout (not executed): [3, 5, 7] Common mistake: Inserting into the list while its iterator is active.
Formal Syntax & Structure
rust syntaxrust
fn iter_mut(&mut self) -> IterMut<'_, T>Working Example
Example Snippetrust
fn main() { use std::collections::LinkedList; let mut q = LinkedList::from([2, 4, 6]); for value in q.iter_mut() { *value += 1; } println!("{:?}", q.into_iter().collect::<Vec<_>>());}