
M02 Resource
- 1.5k installs
- 1.3k repo stars
- Updated May 24, 2026
- actionbook/rust-skills
m02-resource is an agent skill for Rust smart pointer selection covering Box, Rc, Arc, RefCell, and cycle-breaking Weak.
About
The m02-resource skill guides Rust smart pointer and resource management decisions across Box, Rc, Arc, Weak, RefCell, and Cell for heap allocation and shared ownership. Core question asks what ownership pattern the resource needs: single versus shared, single-thread versus multi-thread, and potential cycles requiring Weak. Error-to-design mapping converts heap allocation needs, Rc leaks, RefCell panics, and Arc overhead complaints into design questions rather than blind fixes. Trace up links Rc versus Arc confusion to m07-concurrency and memory leaks to m12-lifecycle. Trace down maps single-owner heap data to Box, shared immutable single-thread to Rc, shared multi-thread to Arc, and interior mutability to RefCell or Cell. Use when choosing smart pointers, reference counting, or RAII Drop patterns in Rust.
- Core question: what ownership pattern does this resource need?
- Single-thread: Rc, Cell, RefCell; multi-thread: Arc, Mutex, RwLock.
- Cycles require Weak in one direction.
- Error mapping: don't just clone — ask who should own data.
- Trace up to m07-concurrency and m03-mutability siblings.
M02 Resource by the numbers
- 1,463 all-time installs (skills.sh)
- +52 installs in the week ending Jul 28, 2026 (Skillselion tracking)
- Ranked #321 of 4,386 Backend & APIs skills by installs in the Skillselion catalog
- Security screen: LOW risk (skills.sh audit)
- Data as of Jul 28, 2026 (Skillselion catalog sync)
m02-resource capabilities & compatibility
- Capabilities
- smart pointer selection by thread context · cycle detection with weak · error to design questioning · sibling skill trace routing
- Use cases
- code review
What m02-resource says it does
What ownership pattern does this resource need?
Yes → One direction must be Weak
npx skills add https://github.com/actionbook/rust-skills --skill m02-resourceAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 1.5k |
|---|---|
| repo stars | ★ 1.3k |
| Security audit | 3 / 3 scanners passed |
| Last updated | May 24, 2026 |
| Repository | actionbook/rust-skills ↗ |
Should I use Box, Rc, or Arc for this Rust resource and how do I avoid reference cycles?
Choose Rust smart pointers Box, Rc, Arc, RefCell for correct resource ownership patterns.
Who is it for?
Rust developers choosing heap allocation and shared ownership patterns.
Skip if: Skip for ownership basics covered by m01-ownership without smart pointer decisions.
When should I use this skill?
User asks Box vs Rc vs Arc, smart pointers, reference counting, heap allocation, or RefCell.
What you get
A justified smart pointer choice matching ownership, threading, and cycle constraints.
- Smart-pointer recommendation
- RAII resource pattern guidance
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:
1. What's the ownership model?
- Single owner → Box or owned value
- Shared ownership → Rc/Arc
- Weak reference → Weak
2. What's the thread context?
- Single-thread → Rc, Cell, RefCell
- Multi-thread → Arc, Mutex, RwLock
3. 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:
"Should I use Arc or Rc?"
↑ Ask: Is this data shared across threads?
↑ Check: m07-concurrency (thread model)
↑ Check: domain-* (performance constraints)| Situation | Trace To | Question |
|---|---|---|
| Rc vs Arc confusion | m07-concurrency | What's the concurrency model? |
| RefCell panics | m03-mutability | Is interior mutability right here? |
| Memory leaks | m12-lifecycle | Where should cleanup happen? |
---
Trace Down ↓
From design to implementation:
"Need single-owner heap data"
↓ Use: Box<T>
"Need shared immutable data (single-thread)"
↓ Use: Rc<T>
"Need shared immutable data (multi-thread)"
↓ Use: Arc<T>
"Need to break reference cycle"
↓ Use: Weak<T>
"Need shared mutable data"
↓ Single-thread: Rc<RefCell<T>>
↓ Multi-thread: Arc<Mutex<T>> or Arc<RwLock<T>>---
Quick Reference
| Type | Ownership | Thread-Safe | Use When |
|---|---|---|---|
Box<T> | Single | Yes | Heap allocation, recursive types |
Rc<T> | Shared | No | Single-thread shared ownership |
Arc<T> | Shared | Yes | Multi-thread shared ownership |
Weak<T> | Weak ref | Same as Rc/Arc | Break reference cycles |
Cell<T> | Single | No | Interior mutability (Copy types) |
RefCell<T> | Single | No | Interior mutability (runtime check) |
Decision Flowchart
Need heap allocation?
├─ Yes → Single owner?
│ ├─ Yes → Box<T>
│ └─ No → Multi-thread?
│ ├─ Yes → Arc<T>
│ └─ No → Rc<T>
└─ No → Stack allocation (default)
Have reference cycles?
├─ Yes → Use Weak for one direction
└─ No → Regular Rc/Arc
Need interior mutability?
├─ Yes → Thread-safe needed?
│ ├─ Yes → Mutex<T> or RwLock<T>
│ └─ No → T: Copy? → Cell<T> : RefCell<T>
└─ No → Use &mut T---
Common Errors
| Problem | Cause | Fix |
|---|---|---|
| Rc cycle leak | Mutual strong refs | Use Weak for one direction |
| RefCell panic | Borrow conflict at runtime | Use try_borrow or restructure |
| Arc overhead | Atomic ops in hot path | Consider Rc if single-threaded |
| Box unnecessary | Data fits on stack | Remove Box |
---
Anti-Patterns
| Anti-Pattern | Why Bad | Better |
|---|---|---|
| Arc everywhere | Unnecessary atomic overhead | Use Rc for single-thread |
| RefCell everywhere | Runtime panics | Design clear ownership |
| Box for small types | Unnecessary allocation | Stack allocation |
| Ignore Weak for cycles | Memory leaks | Design parent-child with Weak |
---
Related Skills
| When | See |
|---|---|
| Ownership errors | m01-ownership |
| Interior mutability details | m03-mutability |
| Multi-thread context | m07-concurrency |
| Resource lifecycle | m12-lifecycle |
Related skills
Forks & variants (1)
M02 Resource has 1 known copy in the catalog totaling 795 installs. They canonicalize to this original listing.
- zhanghandong - 795 installs
How it compares
Use m02-resource after m01-ownership when errors involve smart pointers or shared heap state rather than basic move invalidation.
FAQ
Rc or Arc?
Rc for single-thread shared ownership; Arc when data is shared across threads.
How break reference cycles?
Use Weak for one direction in a cycle instead of strong Rc or Arc references.
Is m02-resource safe to install?
Review the Security Audits panel on this page before installing in production.