We can't find the internet
Attempting to reconnect
Something went wrong!
Attempting to reconnect
← All Rust tracks
Smart Pointers and Interior Mutability
RustChoose between owned, shared and borrowed data using Box, Rc, Weak, RefCell and Cow. Compare runtime borrow checks with arena-based designs.
This track uses Rust. You can make it your practice mode to browse related content across the site.
Your learning sequence
-
1
Not solved yet.
The stack, the heap, and
Box<T>Practice · Easy - 2 Not solved yet. Recursive types need indirection: E0072 Practice · Easy
- 3 Enum layout: niches, guarantees and measurements Read
- 4 Not solved yet. Reduce an enum’s inline size with Box Practice · Medium
-
5
Not solved yet.
Rc<T>: shared ownership by reference counting Practice · Medium - 6 Not solved yet. Trace shared ownership with Rc Practice · Medium
-
7
Not solved yet.
Rc::make_mut: copy-on-write shared data Practice · Hard -
8
Not solved yet.
Rc<str>: sharing interned strings Practice · Medium - 9 Shared does not mean immutable Read
-
10
Not solved yet.
Cell<T>: mutation by moving values in and out Practice · Medium -
11
Not solved yet.
RefCell<T>: borrowing checked at runtime Practice · Medium -
12
Not solved yet.
When
RefCellpanics: re-entrancy and borrows held too long Practice · Hard - 13 Not solved yet. Keep a guard alive with a named binding Practice · Medium
- 14 Not solved yet. RAII: build your own guard Practice · Medium
-
15
Not solved yet.
Rc<RefCell<T>>: shared inboxes and an arena alternative Practice · Hard - 16 Not solved yet. Reference cycles leak memory Practice · Hard
-
17
Not solved yet.
Weak<T>: non-owning references that break cycles Practice · Hard -
18
Not solved yet.
Rc::new_cyclic: self-reference in one step Practice · Hard - 19 Deref, coercion and smart-pointer APIs Read
-
20
Not solved yet.
OnceCell: write-once interior mutability Practice · Medium -
21
Not solved yet.
static mutis dead: what edition 2024 changed Practice · Medium - 22 Not solved yet. Reject stale handles with a generational arena Practice · Hard
- 23 Not solved yet. Build tree paths with an arena and Rc Practice · Hard
- 24 Not solved yet. Drop order in composite structures Practice · Medium
-
25
Not solved yet.
Build
Cell<T>andRefCell<T>from scratch Practice · Hard - 26 Choosing a smart pointer Read
Check yourself
4 questions · not saved while you're signed outUse these questions to check your understanding and compare explanations. Your score does not affect track completion.
0 / 4 correct
What does Rc::clone do in this program?
Choose one answer to reveal the explanations. Answers are kept only while this page is open.
use std::rc::Rc;
fn main() {
let value = Rc::new(String::from("hello"));
{
let other = Rc::clone(&value);
println!("owners: {}", Rc::strong_count(&value));
println!("same allocation: {}", Rc::ptr_eq(&value, &other));
}
println!("owners: {}", Rc::strong_count(&value));
}
Question 1 of 4