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 is ownership in Rust, and why does it matter?
Ownership is Rust's core memory management system: each value has one owner, and when the owner drops, the value is freed. This prevents double-frees and null pointer bugs without garbage collection.
What happens when you assign a variable to another variable in Rust? Example: let x = String::from("hi"); let y = x;
Ownership moves from x to y. x is no longer valid and cannot be used afterward. This is called a 'move,' and attempting to use x will cause a compile error.
What is the difference between copying and moving? Which types copy vs. move by default?
Copying duplicates the value on the stack (cheap); moving transfers ownership. Primitive types (i32, bool, char) implement Copy and are copied by default. Complex types (String, Vec) move by default.
What is a reference, and how do you create one? What does the & symbol mean?
A reference is a non-owning pointer to a value. & creates an immutable reference (borrows the value without taking ownership). Multiple immutable references are allowed; you cannot modify through an immutable reference.
What is a mutable reference (&mut), and what is the key rule about them?
A mutable reference allows modification of the borrowed value. Key rule: only ONE mutable reference can exist to a value at a time in a given scope. You cannot mix mutable and immutable references simultaneously.
What is the 'borrow checker,' and what is it preventing?
The borrow checker is the compiler mechanism that enforces ownership and borrowing rules at compile time. It prevents data races, use-after-free, and double-frees by ensuring references are valid.
What is a lifetime parameter, and why does Rust require them?
A lifetime parameter (e.g., 'a) tracks how long a reference is valid. Rust requires them when a function returns a reference or holds references in structs, to ensure returned/stored references don't outlive their referents.
What is the difference between unwrap(), expect(), and the ? operator for error handling?
unwrap() returns the value or panics if None/Err. expect() does the same with a custom panic message. The ? operator returns early with the error if Err, or continues with the value if Ok—no panic.
What are traits in Rust, and how do they relate to polymorphism?
Traits define shared behavior (methods) that types can implement. They enable compile-time (generics + trait bounds) and runtime (trait objects) polymorphism. Example: impl Display for MyStruct.
What is the difference between 'static and a normal lifetime parameter?
'static means the reference/value lives for the entire program duration. A normal lifetime parameter (e.g., 'a) is a variable placeholder for any lifetime. 'static is the longest possible lifetime.
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 →