m02-resource

Select Rust ownership patterns and smart pointers for memory-safe data structures.

1|Updated May 29, 2026
One-click install
npx skills add https://github.com/simorgh3196/tsuzulint --skill m02-resource
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: m02-resource
Source: https://github.com/simorgh3196/tsuzulint/tree/main/.agents/skills/m02-resource
Command: npx skills add https://github.com/simorgh3196/tsuzulint --skill m02-resource

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill guides Rust developers in selecting correct ownership patterns and smart pointers to manage memory safely and efficiently, reducing leaks and data races.

Core Features & Use Cases

  • Ownership decision guidance: Help decide between Box, Rc, and Arc based on ownership and threading requirements.
  • Pointer safety patterns: Understand when to use Weak, RefCell, and Cell to prevent runtime panics and cycles.
  • Use Case: When building a library with shared state in a multi-threaded context, apply these rules to ensure safe concurrency.

Quick Start

Ask for a recommended ownership pattern for a Rust struct, e.g.: "What pointer type should I use for a graph node with potential cycles?"

Frequently Asked Questions about m02-resource

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
When should I use Rc versus Arc for shared ownership in Rust?

Use Rc for single-threaded shared ownership and Arc for multi-threaded contexts. Rc avoids atomic overhead in single-threaded programs, while Arc ensures safe concurrency across threads.

How do I prevent memory leaks when building a graph with cycles in Rust?

Prevent memory leaks in Rust cyclic graphs by pairing Rc or Arc with Weak references. Weak references break strong reference cycles, allowing nodes to be dropped cleanly without causing leaks.

What is the best way to choose a smart pointer for a Rust data structure?

Choose a Rust smart pointer by evaluating ownership and threading needs: Box for exclusive heap allocation, Rc or Arc for shared ownership, and RefCell or Cell for interior mutability.

When do I need RefCell or Cell for interior mutability in Rust?

Use RefCell for runtime-checked mutable borrows and Cell for Copy types requiring compile-timechecked interior mutability. They enable mutation within immutable structures, preventing data races safely.

Why does Rust require Box for recursive data structure definitions?

Rust requires Box to define recursive data structures because it provides compile-time-known heap allocation size. Without Box, the compiler cannot determine the memory layout of self-referential types.

Can I use smart pointers to manage shared state in a multi-threaded Rust library?

Yes, use Arc for thread-safe reference counting combined with Mutex or RwLock for safe concurrent access. This combination ensures memory safety and prevents data races in multi-threaded shared state.