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
// both a and b are valid

Copy types include: - All integer types (i32, u64, etc.) - Floating point (f32, f64) - Booleans (bool) - Characters (char

Login to see the full exercise.