m02-resource

Installation
Summary

Smart pointer and resource ownership patterns for Rust heap allocation and reference counting.

  • Guides ownership decisions through a three-step model: single vs. shared ownership, single-threaded vs. multi-threaded context, and presence of reference cycles
  • Covers six core types (Box, Rc, Arc, Weak, Cell, RefCell) with a decision flowchart and quick reference table for choosing the right pattern
  • Includes common errors and anti-patterns with fixes, such as using Weak to break cycles, avoiding unnecessary Arc overhead, and preventing RefCell panics
  • Traces design questions upward to concurrency and mutability concerns, and downward to concrete implementation choices
SKILL.md

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
Related skills

More from zhanghandong/rust-skills

Installs
702
GitHub Stars
1.1K
First Seen
Jan 20, 2026