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 Rust's ownership rule, and who can own a value?
Each value has exactly one owner at a time. When the owner goes out of scope, the value is dropped. Ownership can be transferred (moved) to another binding.
What happens when you assign a value to a new variable in Rust?
For non-Copy types (String, Vec, etc.), ownership is *moved*—the original binding becomes invalid. For Copy types (i32, bool, etc.), the value is copied and both bindings remain valid.
What is borrowing, and what are the two types?
Borrowing lets you reference a value without taking ownership. Immutable borrow (&T): read-only, multiple allowed. Mutable borrow (&mut T): exclusive write access, only one at a time per scope.
What is the borrow checker, and what is its main rule?
The borrow checker enforces: you cannot have mutable and immutable borrows of the same value simultaneously. Either multiple immutable borrows OR one mutable borrow—not both.
What is a lifetime, and why does Rust require them in function signatures?
A lifetime is how long a reference is valid. Rust uses lifetime annotations ('a) to ensure references don't outlive the data they point to, preventing dangling pointers at compile time.
What does `let x = String::from("hello"); let y = x;` do, and can you still use `x`?
Ownership of the String moves to `y`. Using `x` afterward is a compile error. This applies to all non-Copy types. Use `clone()` or borrowing if you need to keep `x`.
What is the difference between `&String` and `&str`?
`&String` is a reference to an owned String (heap-allocated). `&str` is a string slice—a view into a sequence of UTF-8 bytes (borrowed, no ownership). `&str` is more flexible and preferred for function parameters.
Why does this code fail: `let mut x = 5; let r1 = &mut x; let r2 = &mut x; println!("{}", r1);`?
Rust allows only one mutable borrow at a time. `r1` and `r2` are both mutable references to `x` in the same scope, violating the rule. Even if you don't use r2, having it declared is an error.
What is the difference between `panic!` and `Result<T, E>`?
`panic!` is unrecoverable—it stops the program. `Result<T, E>` is recoverable error handling (Ok(T) or Err(E)). Use `Result` for expected errors; `panic!` for bugs or impossible states.
What does the `?` operator do, and in what context can you use it?
The `?` operator unwraps a `Result` or `Option`: if Ok/Some, returns the value; if Err/None, returns early from the function with that error/None. Only usable in functions that return `Result` or `Option` (or functions that implement `Try`).
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 →