
M02 Resource
m02-resource guides developers through selecting appropriate smart pointers and resource management patterns in Rust by asking design questions rather than prescribing solutions. It's for Rust developers encountering ownership and memory management challenges who need to understand when to use Box, Rc, Arc, RefCell, or other smart pointers based on their specific ownership model, thread context, and mutability requirements. The skill solves the problem of cargo-cult smart pointer usage by connecting implementation choices back to underlying design decisions about single vs. shared ownership, single-threaded vs. multi-threaded access, and reference cycles.
- skills.sh installs
- 783
- GitHub stars
- 1.3K
- last updated
- Jul 14, 2026
Install
$ npx -y skills add zhanghandong/rust-skills --skill m02-resource --agent claude-codeInstalls into .claude/skills of the current project.
Files
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
| Error | Don't Just Say | Ask Instead |
|---|---|---|
| "Need heap allocation" | "Use Box" | Why can't this be on stack? |
| Rc memory leak | "Use Weak" | Is the cycle necessary in design? |
| RefCell panic | "Use try_borrow" | Is runtime check the right approach? |
| Arc overhead complaint | "Accept it" | Is multi-thread access actually needed? |
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:
Sponsors
Details
- Repository
- github.com/zhanghandong/rust-skills
- Category
- Rust
More from zhanghandong/rust-skills
All 34- M03 Mutability773
- M12 Lifecycle764
- M14 Mental Model751
- M09 Domain750
- M11 Ecosystem747
- M13 Domain Error738
- Rust Trait Explorer731
- Rust Code Navigator728
- Unsafe Checker726
- Domain Cli709
- Rust Symbol Analyzer702
- Rust Call Graph699
- Rust Router698
- Rust Learner688
- Rust Deps Visualizer684
- Rust Skill Creator670
- Domain Web648
- Meta Cognition Parallel635
- Rust Daily635
- Domain Embedded625
- Domain Cloud Native596
- Domain Fintech581
- Domain Ml573
- Domain Iot568