Flashcards · Rust · Free
Rust flashcards, generated for you.
Example Rust study cards to learn from right now — then generate a full set from your own notes (plus a practice quiz) and export to Quizlet or Anki. Free, no account needed.
Example Rust flashcards
What does the `mut` keyword do in Rust?
Declares a variable as mutable, allowing its value to be changed after initialization. Without `mut`, variables are immutable by default.
Explain ownership in Rust.
Each value has one owner. When the owner goes out of scope, the value is dropped. Ownership can be transferred (moved) to another variable, but only one variable owns the value at any time.
What's the difference between `&T` and `&mut T`?
`&T` is an immutable reference (borrow); multiple can exist simultaneously. `&mut T` is a mutable reference; only one can exist at a time, and it has exclusive access to the value.
What is the 'borrow checker' and what does it enforce?
The borrow checker is Rust's compile-time mechanism that enforces the rules: either one mutable reference OR multiple immutable references to the same data, but not both simultaneously.
What happens when you move a value in Rust? Why is this important?
The value's ownership transfers to a new variable; the old variable becomes invalid and cannot be used. This prevents double-free errors and makes memory safety explicit without garbage collection.
What is a 'lifetime' and why does Rust require them for references?
A lifetime is an annotation that specifies how long a reference is valid. Rust uses lifetimes to ensure references don't outlive the data they point to, preventing use-after-free bugs.
Why can't you have both `&mut T` and `&T` to the same data simultaneously?
An immutable reference assumes the data won't change; a mutable reference allows changes. Allowing both would violate the immutable reference's contract, breaking safety guarantees.
What does `Clone` do and how does it differ from `Copy`?
`Clone` explicitly creates a deep copy via `.clone()` method. `Copy` is an implicit, automatic bitwise copy (for small types like integers). `Copy` types are never "moved"—they're always copied.
What is a trait in Rust and how do you implement one?
A trait defines shared behavior (methods/associated functions). Implement with: `impl TraitName for Type { ... }`. Traits are Rust's equivalent to interfaces; they enable polymorphism and code reuse.
What's the gotcha with the following code: `let x = 5; let y = &x; let z = &mut x;`?
This won't compile. `x` is immutable, so you cannot create a mutable reference `&mut x` to it. You must declare `x` as `let mut x = 5;` first.
Make your own Rust study set
Flashcards for related topics
Studying Rust to build with AI? MindloomHQ turns it into real skills — structured courses, agent projects, and certificates.
Explore MindloomHQ →