HomeLearnCoursesHackathonsAccount
Rust for Blockchain Development
Ownership and Borrowing, Conceptually · 1/2

Every piece of data has exactly one owner

At the center of Rust's design is a rule that sounds almost too simple to matter: every piece of data in a Rust program has exactly one owner responsible for it at any given time. When that owner goes out of scope, the data is cleaned up automatically, deterministically, with no garbage collector needed to figure out later whether anything still needs it. This is different from languages that let multiple parts of a program hold uncontrolled references to the same piece of data, and different from languages that hand memory cleanup off to a garbage collector that runs on its own schedule.

Borrowing is the mechanism that lets other parts of a program use data without taking ownership of it. Code can borrow a reference to read data, or borrow it exclusively to modify it, but the compiler enforces strict rules about how many of each kind of borrow can exist at once. Multiple simultaneous readers are fine, but a mutable borrow has to be exclusive, no other reader or writer can be looking at that data at the same moment.