Rust ownership rules, moves, borrowing, mutable references, lifetimes basics and the borrow checker.
45 cards · basic cards · AI-written, checked twice. Edit anything.
- What does it mean to 'own' a value in Rust?
Show answer
A variable is responsible for freeing the value when it goes out of scope.
- State the first rule of ownership.
Show answer
Each value has exactly one owner at a time.
- State the second rule of ownership.
Show answer
When the owner goes out of scope, the value is dropped.
- State the third rule of ownership.
Show answer
You can transfer ownership to another variable through assignment.
- What happens when you assign a value from one variable to another in Rust?
Show answer
Ownership transfers to the new variable, and the original variable becomes invalid.
- What is a 'move' in Rust?
Show answer
The transfer of ownership from one variable to another.
- Can you use a variable after its value has been moved?
Show answer
No, the variable is invalid after the move.
- Which types are moved instead of copied when assigned?
Show answer
Types without the Copy trait, such as String, Vec, and HashMap.
- What is the Copy trait?
Show answer
A trait that marks types whose values can be safely copied instead of moved.
- Do all primitive integer types implement Copy?
Show answer
Yes, all primitive integer types (i8, i16, i32, i64, u8, u16, u32, u64, isize, usize) implement Copy.
- Do floating-point types implement Copy?
Show answer
Yes, both f32 and f64 implement Copy.
- Does the bool type implement Copy?
Show answer
Yes.
- Does String implement Copy?
Show answer
No, String does not implement Copy.
- Does Vec implement Copy?
Show answer
No, Vec does not implement Copy.
- What is a reference in Rust?
Show answer
A pointer to a value that allows you to use the value without taking ownership.