clone() — explicit deep copy (can be expensive). Copy — implicit bitwise copy (always cheap).
clone():
s1.clone().Clone.1let s1 = String::from("hello");2let s2 = s1.clone(); // Deep copy: s2 has its own "hello"3println!("{} {}", s1, s2); // Both valid45let v1 = vec![1, 2, 3];6let v2 = v1.clone(); // v2 is a new Vec with copied elements
Copy trait:
Copy, it must also implement Clone.1let x = 5; // i32 implements Copy2let y = x; // Implicit copy — x is still valid3println!("{} {}", x, y); // Both print 545let a = (1, "hello"); // Tuple of Copy types → Copy6let b = a;
When to use:
clone() when you need explicit duplication (e.g., before moving).Common mistakes:
.clone() unnecessarily when borrowing would work.String doesn't implement Copy — must clone.Copy for types with heap data — compiler rejects it.