std-method

LinkedList::append

Join the second list after the first by transferring its nodes. With the default allocator this operation is constant time; the donor becomes empty. Expected stdout (not executed): [1, 2, 3, 4] true Common mistake: Assuming both lists keep independent copies of their items.

Formal Syntax & Structure

rust syntaxrust
fn append(&mut self, other: &mut Self)

Working Example

Example Snippetrust
fn main() {    use std::collections::LinkedList;    let mut a = LinkedList::from([1, 2]);    let mut b = LinkedList::from([3, 4]);    a.append(&mut b);    println!("{:?} {}", a.into_iter().collect::<Vec<_>>(), b.is_empty());}
Rust Reference