Home / Community / Rust Systems Programming - Ownership, Lifetimes & Borrowing
Public

Rust Systems Programming - Ownership, Lifetimes & Borrowing

Master memory safety without a garbage collector, strict borrowing rules, lifetimes, smart pointers, and concurrency in Rust with these high-yield flashcards.

20 accessible of 20 cards

Card Preview

20 accessible of 20 cards

A quick, read-only look at the deck content.

Term

Three Fundamental Rules of Ownership

Definition

1. Each value in Rust has an owner (a variable).
2. There can only be one owner at a time.
3. When the owner goes out of scope, the value is dropped (freed).

Term

Move Semantics vs. Copy Semantics

Definition

Types implementing the Copy trait perform bitwise duplication on assignment. Types without Copy (e.g., String, Vec) transfer ownership via a move, rendering the original variable uninitialized and unusable.

Term

The Borrow Checker

Definition

A static analysis tool within the Rust compiler that enforces borrowing rules, preventing memory safety bugs such as dangling pointers, double frees, and data races at compile time.

Term

Aliasing XOR Mutability Rule

Definition

At any given point in a scope, you can have either:
  • Any number of immutable references (&T), OR
  • Exactly one mutable reference (&mut T).
You can never have both simultaneously.

Term

Non-Lexical Lifetimes (NLL)

Definition

A compiler feature that determines reference lifetimes based on actual usage in the control flow graph, rather than strict lexical block scopes ({}), making borrowing more flexible.

Term

Lifetime Annotations ('a)

Definition

Explicit syntax (e.g., fn foo<'a>(x: &'a str) -> &'a str) used to tell the compiler how the lifetimes of different references relate to each other, ensuring return references remain valid.

Term

Lifetime Elision Rules

Definition

Three deterministic heuristics compiler rules that allow developers to omit explicit lifetime annotations in common function signature patterns:
1. Each elided input parameter gets its own lifetime.
2. If there is one input lifetime, it is assigned to all output lifetimes.
3. If &self or &mut self is an input, its lifetime is assigned to all output lifetimes.

Term

The Static Lifetime ('static)

Definition

A special lifetime indicating that data lives for the entire execution of the program (e.g., string literals &'static str), or a trait bound specifying a type contains no non-static references.