20 cards · Public · Shuffle

Rust Programming Language - Ownership, Borrowing & Lifetimes

Master Rust's core memory safety paradigm with this high-yield flashcard deck covering ownership rules, move semantics, reference aliasing, lifetime elision, and smart pointers.

Cards in this deck

(20 cards)

Preview terms and definitions before starting your study session.

#1
Term
What are the three fundamental Ownership Rules in Rust?
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 automatically dropped.
#2
Term
What is a Scope in Rust and how does it affect variables?
Definition
A scope is a block of code enclosed by curly braces {}. When a variable enters scope, it becomes valid. When it exits scope, Rust calls the drop function to free its memory immediately.
#3
Term
What are Move Semantics in Rust?
Definition
When a non-Copy variable is assigned to another variable, passed to a function, or returned, ownership of the resource transfers to the new owner. The original variable is invalidated and cannot be accessed.
#4
Term
What is the Copy trait in Rust?
Definition
A marker trait for types whose values exist entirely on the stack and can be duplicated via a cheap bitwise copy. Types implementing Copy (e.g., i32, bool, char) do not transfer ownership on assignment.
#5
Term
What is the difference between the Copy and Clone traits?
Definition
Copy is implicit and performs an inexpensive bitwise copy for stack-allocated types. Clone is explicit, requiring a .clone() call, and can perform expensive deep copies of heap-allocated data (e.g., String or Vec).
#6
Term
What is Borrowing in Rust?
Definition
Borrowing is creating a reference to a value rather than taking ownership of it. References allow temporary access to data without destroying or moving the original owner.
#7
Term
What is an Immutable Reference (&T)?
Definition
An immutable reference allows reading data without modifying it. You can have multiple immutable references to the same data active at the same time, as long as no mutable reference exists.
#8
Term
What is a Mutable Reference (&mut T)?
Definition
A mutable reference permits reading and modifying data. To prevent data races, you can have only one mutable reference to a piece of data in a given scope, with zero coexisting immutable references.
Showing 8 of 20 cards in this deck.
Study All Now