Flashcard Deck · 21 cards · Public

Rust Programming - Ownership, Borrowing & Lifetimes

Master Rust's core memory safety paradigms without a garbage collector. This high-yield deck covers ownership rules, borrowing constraints, lifetime annotations, smart pointers, and concurrency traits.

Cards in this deck

(21 cards)

Preview terms and definitions before starting your study session.

#1
Term
The Three Rules of Ownership
Definition
1. Each value in Rust has an owner represented by a variable.
2. There can only be one owner at a time.
3. When the owner goes out of scope, the value is automatically dropped.
#2
Term
Move Semantics
Definition
When a non-Copy variable is assigned to another variable or passed to a function, ownership is transferred (moved). The original variable becomes invalid and cannot be used afterward.
#3
Term
Copy vs. Clone Traits
Definition
  • Copy: Implemented for types stored entirely on the stack (e.g., i32, bool). Bitwise duplicate occurs implicitly without invalidating the source.
  • Clone: Requires an explicit .clone() call to perform a deep, potentially expensive heap allocation duplicate.
#4
Term
Immutable Borrowing (&T)
Definition
Allows creating references to data without taking ownership. Multiple immutable references (&T) to the same resource can exist simultaneously because reading data concurrently is thread-safe.
#5
Term
Mutable Borrowing (&mut T)
Definition
Allows modifying data without taking ownership. Only one mutable reference to a piece of data can exist in a given scope at a time.
#6
Term
Aliasing XOR Mutability Rule
Definition
You can have either any number of immutable references (&T) OR exactly one mutable reference (&mut T), but never both in the same scope simultaneously. This prevents data races at compile time.
#7
Term
Non-Lexical Lifetimes (NLL)
Definition
An enhancement to Rust's borrow checker where a reference's lifetime ends at the point of its last usage, rather than at the end of the enclosing scope block (}).
#8
Term
Lifetime Annotations ('a)
Definition
Generics that begin with an apostrophe (e.g., 'a). They tell the compiler how the lifetimes of different references in a function's parameters and return value relate to each other without changing actual runtimes.
Showing 8 of 21 cards in this deck.
Study All Now