Master Rust Ownership And Borrowing Explained with 120 free flashcards. Study using spaced repetition and focus mode for effective learning in Programming.
Each value in Rust has an owner. There can only be one owner at a time. When the owner goes out of scope, the value is dropped.
It is dropped — its drop function runs and its memory is freed.
drop, from the Drop trait, is called automatically at the end of the variable's scope.
A transfer of ownership: assigning a value to another variable or passing it to a function moves the value, invalidating the source binding.
Moving avoids double-free bugs and keeps the type system simple — for stack-allocated types that own heap data (like String), copying the pointer would leave two owners.
No. s1 is invalidated by the move; using it is a compile-time error.
Copy and Clone. Types implementing Copy (e.g. integers, bool, char, tuples of Copy types) are copied on assignment; Clone is an explicit .clone() method.
Copy is an implicit, bitwise copy marker with no custom behavior; Clone is an explicit method (.clone()) that may perform arbitrary, potentially expensive duplication.
No. The compiler rejects types that implement both Copy and Drop, because Copy implies no special cleanup is needed.
Copy is a marker trait (a unit trait) that requires implementing Clone.
A reference (&T for shared, &mut T for mutable) is a non-owning pointer to a value, governed by the borrow checker.
Borrowing is the act of passing a reference to a value rather than transferring ownership, so the original owner retains it.
Flashcards
Flip to reveal
Focus Mode
Spaced repetition
Multiple Choice
Test your knowledge
Type Answer
Active recall
Learn Mode
Multi-round mastery
Match Game
Memory challenge