Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
actionbook avatar

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)
At a glance

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
From the docs

What m02-resource says it does

What ownership pattern does this resource need?
SKILL.md
Yes → One direction must be Weak
SKILL.md
npx skills add https://github.com/actionbook/rust-skills --skill m02-resource

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs1.5k
repo stars1.3k
Security audit3 / 3 scanners passed
Last updatedMay 24, 2026
Repositoryactionbook/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

SKILL.mdMarkdownGitHub ↗

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

ErrorDon't Just SayAsk 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)
SituationTrace ToQuestion
Rc vs Arc confusionm07-concurrencyWhat's the concurrency model?
RefCell panicsm03-mutabilityIs interior mutability right here?
Memory leaksm12-lifecycleWhere 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

TypeOwnershipThread-SafeUse When
Box<T>SingleYesHeap allocation, recursive types
Rc<T>SharedNoSingle-thread shared ownership
Arc<T>SharedYesMulti-thread shared ownership
Weak<T>Weak refSame as Rc/ArcBreak reference cycles
Cell<T>SingleNoInterior mutability (Copy types)
RefCell<T>SingleNoInterior 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

ProblemCauseFix
Rc cycle leakMutual strong refsUse Weak for one direction
RefCell panicBorrow conflict at runtimeUse try_borrow or restructure
Arc overheadAtomic ops in hot pathConsider Rc if single-threaded
Box unnecessaryData fits on stackRemove Box

---

Anti-Patterns

Anti-PatternWhy BadBetter
Arc everywhereUnnecessary atomic overheadUse Rc for single-thread
RefCell everywhereRuntime panicsDesign clear ownership
Box for small typesUnnecessary allocationStack allocation
Ignore Weak for cyclesMemory leaksDesign parent-child with Weak

---

Related Skills

WhenSee
Ownership errorsm01-ownership
Interior mutability detailsm03-mutability
Multi-thread contextm07-concurrency
Resource lifecyclem12-lifecycle

Related skills

Forks & variants (1)

M02 Resource has 1 known copy in the catalog totaling 795 installs. They canonicalize to this original listing.

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.

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.