Ownership rules summary cheat sheet

Rust ownership rules ensure memory safety by assigning a single owner to each value, transferring ownership on assignment, and automatically freeing memory when the owner goes out of scope.

Rust ownership is a set of rules ensuring memory safety without a garbage collector by enforcing that each value has exactly one owner, ownership transfers on assignment, and values are dropped when their owner goes out of scope.

let s1 = String::from("hello");
let s2 = s1; // Ownership moves to s2; s1 is invalid
// println!("{}", s1); // Error: use of moved value
println!("{}", s2); // Valid

To share data without moving ownership, use references (borrowing) with & for immutable access or &mut for mutable access, ensuring no simultaneous mutable and immutable borrows.