m03-mutability

Diagnose Rust mutability and borrowing errors with design guidance.

Updated Feb 12, 2026
One-click install
npx skills add https://github.com/jmduea/emotiv-cortex-rs --skill m03-mutability-jmduea
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: m03-mutability
Source: https://github.com/jmduea/emotiv-cortex-rs/tree/main/.github/skills/m03-mutability
Command: npx skills add https://github.com/jmduea/emotiv-cortex-rs --skill m03-mutability-jmduea

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Rust developers frequently encounter mutability and borrowing errors such as E0596, E0499, E0502, or runtime RefCell panics, which block compilation and lead to unsafe code patterns. This Skill guides users to understand the root cause, evaluate design decisions, and choose the appropriate mutability primitive.

Core Features & Use Cases

  • Diagnostic prompts that transform compiler errors into design questions.
  • Decision tables for selecting &mut, Cell, RefCell, Mutex, RwLock, or atomic types based on thread context.
  • Trace up/down maps linking mutability conflicts to domain design or concurrency considerations.
  • Anti‑pattern warnings and recommended refactorings for single‑thread and multi‑thread scenarios.
  • Quick reference tables summarizing runtime costs and thread‑safety characteristics.

Quick Start

Ask the mutability skill to analyse a Rust borrowing error and suggest a safe refactoring.

Frequently Asked Questions about m03-mutability

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

FAQPage Schema
How do I resolve Rust mutability and borrowing errors like E0596 or E0502?

To resolve Rust mutability and borrowing errors, analyze the compiler error to understand the root conflict, then choose a safe refactoring pattern using primitives like &mut or RefCell based on your thread context.

When should I use Cell, RefCell, Mutex, or RwLock for interior mutability in Rust?

Select an interior mutability primitive by checking thread context: use Cell or RefCell for single-threaded scenarios, and apply Mutex or RwLock for multi-threaded concurrency to ensure safe access.

Why does my Rust RefCell panic at runtime and how can I fix it?

A Rust RefCell panics at runtime when borrowing rules are violated, such as overlapping mutable borrows. Fix this by refactoring the access logic to prevent simultaneous mutable borrows.

What is the best way to choose between &mut and interior mutability for Rust compiler errors?

The best way to choose between &mut and interior mutability is to evaluate runtime costs and thread-safety needs, using &mut for direct exclusive access and interior types for shared state structures.

What are common anti-patterns when fixing Rust borrowing conflicts?

Common anti-patterns when fixing Rust borrowing conflicts include excessive cloning or unsafe blocks. Replace them with recommended refactorings and appropriate mutability primitives for your thread context.