FlashKeepers

Rust · College · College and University

Rust I: Ownership and Borrowing

Rust ownership rules, moves, borrowing, mutable references, lifetimes basics and the borrow checker.

About this set

45 basic cards for College Rust. Set 1 of 6 in Rust. It opens with "What does it mean to 'own' a value in Rust?" and "State the first rule of ownership". Study it alongside the other College sets below.

45 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone

Opens in your browser, no account. Get the iPhone and iPad app · Android app

What does it mean to 'own' a value in Rust?
Show answerA variable is responsible for freeing the value when it goes out of scope.
State the first rule of ownership.
Show answerEach value has exactly one owner at a time.
State the second rule of ownership.
Show answerWhen the owner goes out of scope, the value is dropped.
State the third rule of ownership.
Show answerYou can transfer ownership to another variable through assignment.
What happens when you assign a value from one variable to another in Rust?
Show answerOwnership transfers to the new variable, and the original variable becomes invalid.
What is a 'move' in Rust?
Show answerThe transfer of ownership from one variable to another.
Can you use a variable after its value has been moved?
Show answerNo, the variable is invalid after the move.
Which types are moved instead of copied when assigned?
Show answerTypes without the Copy trait, such as String, Vec, and HashMap.
What is the Copy trait?
Show answerA trait that marks types whose values can be safely copied instead of moved.
Do all primitive integer types implement Copy?
Show answerYes, all primitive integer types (i8, i16, i32, i64, u8, u16, u32, u64, isize, usize) implement Copy.
Do floating-point types implement Copy?
Show answerYes, both f32 and f64 implement Copy.
Does the bool type implement Copy?
Show answerYes.
Does String implement Copy?
Show answerNo, String does not implement Copy.
Does Vec implement Copy?
Show answerNo, Vec does not implement Copy.
What is a reference in Rust?
Show answerA pointer to a value that allows you to use the value without taking ownership.

30 more cards in the app

Study this set free