How to copy an array in Rust?
In Rust, to copy an array into another we can simply use the functionclone()
. which will clone all elements into another.Example of copying an array in Rust
fn main() {
let arr = ["a","b","c"];
let mut another = arr.clone();
println!("copy of arr = {:?} ", another);
}
Output
copy of arr = ["a", "b", "c"]