Rustfully

What will happen when we run this code in Rust?

let x = 42;
let y = x;
dbg!(x, y);

3 months ago | [YT] | 86



@ziyan8862

Simple types like i32 are Copy, so assigning them just copies the value. Ownership rules mainly apply to complex types like String, which are moved by default. Arrays are Copy if their elements are Copy and the size is small. But Vec<T> is always moved, even if its elements are Copy.

3 months ago (edited) | 10

@greenyxd7298

almost all literal types impl Copy. which messes with the ownership system. so if you try to understand ownership and borrowing, always use your own structs to experiment!

1 month ago | 1