Guides Rust developers in choosing smart pointers and ownership patterns such as Box, Rc, Arc, Weak, Cell and RefCell.
- What it does
- This skill is a decision guide for Rust resource management. It walks through ownership models, thread context and reference cycles, then maps situations to types like Box, Rc, Arc, Weak, Cell and RefCell. It also lists common errors, anti-patterns and related topics to consult when a pointer choice is unclear.
- When to use it
- Use it when deciding between smart pointers, such as Box versus Rc or Arc versus Rc, or when diagnosing issues like Rc memory leaks, RefCell panics or unnecessary Arc overhead. It is also useful when reasoning about heap allocation, reference counting, RAII or Drop behavior.
- Requirements
- No tools, packages or credentials are required; it is an instructions-only skill with no scripts.
Resource Management
Layer 1: Language Mechanics
Core Question
What ownership pattern does this resource need?
Before choosing a smart pointer, understand:
- Is ownership single or shared?
- Is access single-threaded or multi-threaded?
- Are there potential cycles?
Error → Design Question
Thinking Prompt
Before choosing a smart pointer:
-
What's the ownership model?
- Single owner → Box or owned value
- Shared ownership → Rc/Arc
- Weak reference → Weak
-
What's the thread context?
- Single-thread → Rc, Cell, RefCell
- Multi-thread → Arc, Mutex, RwLock
-
Are there cycles?
- Yes → One direction must be Weak
- No → Regular Rc/Arc is fine
Trace Up ↑
When pointer choice is unclear, trace to design:
Trace Down ↓
From design to implementation:
Quick Reference
Decision Flowchart
Common Errors
Anti-Patterns
Related Skills