clone() — explicit deep copy (can duplicate heap data). Copy — implicit bitwise copy (always cheap).
clone():
.clone() method.Clone trait.1let s1 = String::from("hello");2let s2 = s1.clone(); // s2 owns its own copy of "hello"3println!("{} {}", s1, s2); // Both valid45let v1 = vec![1, 2, 3];6let v2 = v1.clone(); // v2 is a separate Vec
Copy trait:
Clone if implementing Copy.1let x: i32 = 42; // i32 implements Copy2let y = x; // Implicit copy — x still valid3println!("{} {}", x, y); // 42 4245let tuple = (1, 2.0, true); // All Copy → tuple is Copy6let copy = tuple;
When to use:
clone() when you need explicit ownership (before moving).Common mistakes:
.clone() when borrowing would work — performance hit.String implements Copy — it doesn't (heap data).Copy for heap types — compiler rejects it.