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-code

Installs 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

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:

Sponsors

Details

Repository
github.com/zhanghandong/rust-skills
Category
Rust

More from zhanghandong/rust-skills

All 34

Recommended

More Rust
1zhanghandong avatarm03-mutabilityzhanghandong/rust-skillsm03 mutability773skills.sh installs
2zhanghandong avatardomain-webzhanghandong/rust-skillsdomain web648skills.sh installs
3zhanghandong avatardomain-iotzhanghandong/rust-skillsdomain iot568skills.sh installs
4warpdotdev avatarfix-errorswarpdotdev/common-skillsFix compilation errors, linting issues, and test failures in the warp Rust codebase. Covers presubmit checks, WASM-specific errors, and running specific tests. 28.7Kskills.sh installs
5wshobson avatarmemory-safety-patternswshobson/agentsImplement memory-safe programming with RAII, ownership, smart pointers, and resource management across Rust, C++, and C. Use when writing safe systems code, man12.2Kskills.sh installs
6dotnet avatartest-gap-analysisdotnet/skillsPerforms pseudo-mutation analysis on production code in any language to find gaps in existing tests. Use when the user asks to find weak or shallow tests, disco4.3Kskills.sh installs