Clone and Copy
clone makes a deep copy. Copy types such as integers are copied automatically.
Example
fn main() {
let a = String::from("x");
let b = a.clone();
println!("{} {}", a, b);
let n = 5; let m = n;
println!("{} {}", n, m);
}Result
x x 5 5
Exercise
Deep copy.
a.()
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.