Move, Copy and Clone
Assigning a heap value moves ownership. Simple types such as integers implement Copy and are duplicated. clone makes an explicit deep copy.
Example
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
Make a deep copy.
s.()
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.