std-method

Vec::append

Move all elements from another vector to the end of this one, preserving their order. The source remains a valid empty vector. This does not promise that its capacity becomes zero. Expected stdout (not executed): ["A", "B", "C"] true Common mistake: Expecting append to clone elements or consume the source binding.

Formal Syntax & Structure

rust syntaxrust
pub fn append(&mut self, other: &mut Vec<T>)

Working Example

Example Snippetrust
fn main() {    let mut first = vec![String::from("A")];    let mut second = vec![String::from("B"), String::from("C")];    first.append(&mut second);    println!("{first:?} {}", second.is_empty());}
Rust Reference