Choosing Rust smart pointers by ownership model, thread context, and reference cycles, with a decision flowchart.

skills.sh installs
3.7K
GitHub stars
1.6K
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers the core pointers Box, Rc, Arc, Weak, Cell, and RefCell, plus Mutex and RwLock for shared mutable data
  • Includes a decision flowchart, a quick-reference table, common errors with fixes, and anti-patterns to avoid
  • Guides choices by asking whether ownership is single or shared, whether access is single-threaded, and whether cycles exist
  • Designed for Rust developers deciding between Box and Rc, or Rc and Arc, and debugging leaks or RefCell panics

Install

$ npx -y skills add actionbook/rust-skills --skill m02-resource -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

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

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:

Details

Repository
github.com/actionbook/rust-skills
Category
Rust
First seen
May 16, 2026

More from actionbook/rust-skills

All 38

Similar to M02 Resource

More Rust