std-method

LinkedList::back_mut

Borrow the last element mutably for a targeted update. Other accesses requiring the list must wait until the exclusive borrow is finished. Expected stdout (not executed): Some(14) Common mistake: Holding the reference while trying to mutate the list itself.

Formal Syntax & Structure

rust syntaxrust
fn back_mut(&mut self) -> Option<&mut T>

Working Example

Example Snippetrust
fn main() {    use std::collections::LinkedList;    let mut q = LinkedList::from([4, 7]);    if let Some(last) = q.back_mut() { *last *= 2; }    println!("{:?}", q.back());}
Rust Reference