// Created on savesnippets.com ยท https://savesnippets.com/DsBJ40Ph0Fk2tI fn main() { // i32 is Copy โ€” assignment duplicates the value let a: i32 = 42; let b = a; println!("{a} {b}"); // both still valid: 42 42 // String is NOT Copy โ€” assignment moves let s1 = String::from("hello"); let s2 = s1; // println!("{s1}"); // โŒ moved println!("{s2}"); // Use .clone() when you actually want a duplicate let s3 = String::from("hello"); let s4 = s3.clone(); println!("{s3} {s4}"); // Derive Copy + Clone on your own struct (only if every field is Copy) #[derive(Copy, Clone, Debug)] struct Point { x: f64, y: f64 } let p = Point { x: 1.0, y: 2.0 }; let q = p; // copied, not moved println!("{p:?} {q:?}"); }