m02-resource

Guides choosing Rust smart pointers for memory management and ownership patterns.

51|6|Updated Mar 28, 2019
One-click install
npx skills add https://github.com/Mte90/dotfiles --skill m02-resource-mte90
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: m02-resource
Source: https://github.com/Mte90/dotfiles/tree/main/.config/opencode/skills/m02-resource
Command: npx skills add https://github.com/Mte90/dotfiles --skill m02-resource-mte90

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps developers choose the correct smart pointer in Rust, preventing memory leaks, runtime panics, and unnecessary overhead by guiding them through ownership, threading, and cycle considerations.

Core Features & Use Cases

  • Smart Pointer Selection: Provides a decision-making framework for Box, Rc, Arc, Weak, Cell, and RefCell.
  • Error Prevention: Details common pitfalls like reference cycles and RefCell panics, offering solutions.
  • Use Case: When unsure whether to use Arc<Mutex<T>> or Rc<RefCell<T>> for shared mutable data in a multi-threaded application, this Skill guides the decision based on concurrency needs.

Quick Start

Use the m02-resource skill to understand when to use Box versus Rc for heap allocation.

Frequently Asked Questions about m02-resource

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

FAQPage Schema
How do I choose the right Rust smart pointer for heap allocation and ownership?

Choosing the right Rust smart pointer depends on your ownership requirements, selecting Box for exclusive heap allocation and Rc or Arc for shared ownership scenarios.

When should I use Arc<Mutex<T>> versus Rc<RefCell<T>> for shared mutable data?

Use Arc<Mutex<T>> for shared mutable data in multi-threaded applications requiring thread safety, whereas Rc<RefCell<T>> suits single-threaded contexts with interior mutability needs.

How does interior mutability work with Cell and RefCell in Rust?

Interior mutability with Cell and RefCell allows mutating immutable references, where Cell copies values and RefCell enforces borrowing rules at runtime to prevent panics.

Why do Rust smart pointers cause memory leaks and runtime panics?

Rust smart pointers cause memory leaks and runtime panics through reference cycles in Rc or invalid borrowing in RefCell, preventable by using Weak pointers and safe borrowing patterns.

What is the best way to prevent reference cycles when using Rc in Rust?

The best way to prevent reference cycles with Rc in Rust is using Weak pointers for child references, breaking strong cycles to avoid memory leaks while maintaining access to the hierarchy.