What is the best way to concatenate vectors in Rust?
@lebyy▲ 0 net votes
Problem: Is it even possible to concatenate vectors in Rust? If so, is there an elegant way to do so? I have something like this: let mut a = vec![1, 2, 3]; let b = vec![4, 5, 6]; for val in &b { a.push(val); } Does anyone know of a better way? Fix (from the top answer): The structure std::vec::Vec has method append() : fn append(&mut self, other: &mut Vec<T>) Moves all the elements of other into Self , leaving other empty. From your example, the following code will concatenate two vectors by mutating a and b : fn main() { let mut a = vec![1, 2, 3]; let mut b = vec![4, 5, 6];…