From the bookA pointer is a general concept for a variable that contains an address in memory. This address refers to, or “points at,” some other data.Read in context
Scenarioreferences
You only need to refer to some data. You don't need any extra capabilities, and you want zero overhead. Which kind of pointer should you use?
From the bookThey don’t have any special capabilities other than referring to data, and they have no overhead.Read in context
RecallreferencesChoose TWO
Which TWO statements about references in Rust are true?
From the bookReferences are indicated by the & symbol and borrow the value they point to.Read in context
Interviewsmart-pointers
An interviewer asks: "Are smart pointers a Rust invention?" What's the right answer?
From the bookThe concept of smart pointers isn’t unique to Rust: Smart pointers originated in C++ and exist in other languages as well.Read in context
Recallownership
How do references and smart pointers differ in terms of ownership?
From the bookWhile references only borrow data, in many cases smart pointers own the data they point to.Read in context
Scenariorc
Some data in your program needs multiple owners, and it should be cleaned up automatically once no owners remain. Which smart pointer should you use?
From the bookThis pointer enables you to allow data to have multiple owners by keeping track of the number of owners and, when no owners remain, cleaning up the data.Read in context
Recallderef-dropChoose TWO
Which TWO statements about the Deref and Drop traits are true?
From the bookThe Deref trait allows an instance of the smart pointer struct to behave like a reference so that you can write your code to work with either references or smart pointers. The Drop trait allows you to customize the code that’s run when an instance of the smart pointer goes out of scope.Read in context
Scenariosmart-pointers
You want to write your own smart pointer. It should behave like a reference and run custom code when it goes out of scope. How do you build it?
From the bookSmart pointers are usually implemented using structs. Unlike an ordinary struct, smart pointers implement the Deref and Drop traits.Read in context
Recallrefcell
What does RefCell<T> do?
From the bookRef<T> and RefMut<T>, accessed through RefCell<T>, a type that enforces the borrowing rules at runtime instead of compile timeRead in context
Recallinterior-mutability
What is the interior mutability pattern?
From the bookIn addition, we’ll cover the interior mutability pattern where an immutable type exposes an API for mutating an interior value.Read in context
Recallreference-cycles
What problem can reference cycles cause?
From the bookWe’ll also discuss reference cycles: how they can leak memory and how to prevent them.Read in context