How to concatenate two vectors in Rust?
In Rust, the structurestd::vec::Vec
has method append()
:fn append(&mut self, other: &mut Vec<T>)
Example of vectors concatenation in Rust
fn main() {
let mut a = vec![1, 2, 3];
let mut b = vec![4, 5, 6];
a.append(&mut b);
println!("concatenated vector {:?}", a);
}
Output
concatenated vector [1, 2, 3, 4, 5, 6]