clone() — explicit deep copy (duplicates all data). Copy — implicit bitwise copy (always cheap).
clone():
.clone() method.Clone.1let s1 = String::from("hello");2let s2 = s1.clone(); // s2 owns its own "hello"3println!("{} {}", s1, s2); // Both valid45let v1 = vec![1, 2, 3];6let v2 = v1.clone(); // v2 is separate Vec
Copy trait:
Clone.1let x: i32 = 42;2let y = x; // Implicit copy3println!("{} {}", x, y); // 42 4245let a = [1, 2, 3]; // [i32; 3] is Copy6let b = a;
When to use:
clone() for explicit ownership.Common mistakes:
String is Copy — it isn't.Copy for heap types — compiler rejects.