Ownership in Rust

Rust’s memory model centers around the idea that every value has a single owner. This is enforced by the borrow checker.

In Rust, an owner calls destructors when its values’ lifetimes end. Values cannot outlive their owner.

Ownership can be transferred in Rust either through assignments or passing data as an argument or return value. For example, the following code transfer ownership from a to b. After being moved, a can no longer be used. And when the scope end, Rust only deallocate the box on behave of b rather than a.

let a = Box::new([0; 1_000_000]);
let b = a;