Pybites Logo Rust Platform

Copy vs Clone

Easy +2 pts

In the previous exercise, you learned that assignment moves ownership. But wait — this works fine:

let x = 42; let y = x; println!("{}", x); // still valid!

Why didn't x move? Because integers implement the Copy trait.

Copy types: stack-only data

Types that are small and live entirely on the stack can be copied instead of moved:

let a: i32 = 5; let b = a; // a is copied, not moved // …

Login to see the full exercise.