To concatenate two vectors in Rust, you can use the `extend` method or the `append` method.
In this example,
vector1
and vector2
.extend
method on vector1
with vector2
as an argument.extend
method appends all elements from vector2
to vector1
.vector1
to standard output.let mut vector1 = vec![1, 2, 3];
let vector2 = vec![4, 5, 6];
vector1.extend(vector2);
println!("{:?}", vector1);
[1, 2, 3, 4, 5, 6]
In this example,
vector1
and vector2
.append
method on vector1
with vector2
as an argument.append
method appends all elements from vector2
to vector1
.vector1
to standard output.let mut vector1 = vec!['a', 'b', 'c'];
let vector2 = vec!['d', 'e', 'f'];
vector1.append(&mut vector2);
println!("{:?}", vector1);
["a", "b", "c", "d", "e", "f"]
In this tutorial, we learned How to Concatenate Two Vectors in Rust language with well detailed examples.