Fundamentals21 / 42
Up next

Copy vs move

fn main() {
    // i32 is Copy
    let a = 5;
    // a is copied; both usable
    let b = a;
    println!("{a} {b}");

    // String owns heap data
    let s = String::from("hi");
    // s is MOVED into t
    let t = s;
    // println!("{s}");          // error: s was moved
    println!("{t}");
}
What you're solving

simple types copy; owned types move