m02-resource

Guide Rust smart pointer selection for ownership, mutability, and thread safety.

2|Updated Mar 8, 2026
One-click install
npx skills add https://github.com/mo4islona/sqd-query-engine --skill m02-resource-mo4islona
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: m02-resource
Source: https://github.com/mo4islona/sqd-query-engine/tree/main/.claude/skills/m02-resource
Command: npx skills add https://github.com/mo4islona/sqd-query-engine --skill m02-resource-mo4islona

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) and assets (resource) components.

What problem does it solve?

It helps developers understand how to efficiently manage resources and ownership in Rust programming, reducing errors related to memory leaks and unsafe references.

Core Features & Use Cases

  • Ownership pattern guidance: Explains when to use Box, Rc, Arc, Weak, RefCell, and Cell.
  • Design decision prompts: Provides questions to choose the appropriate smart pointer based on ownership, threading, and cycle considerations.
  • Error prevention: Offers strategies to avoid common pitfalls like reference cycles and runtime borrow panics.

Quick Start

Use this skill to determine whether to use Rc or Arc for shared ownership scenarios in multi-threaded Rust applications.

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?

Rust smart pointers like Box, Rc, Arc, and RefCell enforce compile-time or runtime borrow rules to ensure memory safety. They automatically deallocate resources when reference counts reach zero, preventing memory leaks without garbage collection.

How do I prevent reference cycles causing memory leaks with Rust smart pointers?

Use Weak references to break reference cycles in Rust. Weak pointers hold a non-owning reference to data, preventing strong count increments that can cause memory leaks when nested structures like graphs reference each other cyclically.

What is the difference between Cell and RefCell for interior mutability in Rust?

Cell provides interior mutability by copying values, suitable for simple Copy types without borrowing. RefCell enforces borrow rules at runtime, allowing mutable borrows of complex types but potentially panicking if borrow rules are violated.

How do I choose the right smart pointer for thread safety in Rust?

Choose Arc for thread-safe shared ownership in multi-threaded Rust. Combine Arc with Mutex or RwLock for safe mutable access across threads, ensuring data races are prevented during concurrent resource modifications.

Why does RefCell panic at runtime in Rust and how can I avoid it?

RefCell panics when runtime borrow rules are violated, such as having multiple mutable borrows simultaneously. Avoid panics by carefully managing borrow scopes and ensuring mutable borrows do not overlap during execution.