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

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.

20 accessible of 20 cards

Card Preview

20 accessible of 20 cards

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

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.

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.

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.

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.

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).

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.

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.

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.