# m03-mutability

A Rust skill for mutability trouble: it walks from borrow-checker errors to a decision about the data, not just another mut.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 3300 installs · ★ 1545
- Author: actionbook
- License: not stated · policy=link-only · description only; the file stays with the author
- Source: https://github.com/actionbook/rust-skills/tree/HEAD/skills/m03-mutability/SKILL.md
- Updated: 2026-08-23
- HTML: https://affpapa.org/en/nevibecode/skills/m03-mutability

## What it does

The skill fires on E0596, E0499, E0502, on “cannot borrow as mutable” messages and on `RefCell` panics. Its first move is a question: does this value need to change at all, and who gets to change it? Sometimes the answer is a new value instead of a mutation.

Choosing interior mutability comes down to two facts in the reference tables: is the type `Copy`, and does the code cross threads. `Cell<T>` covers `Copy` types on one thread; `RefCell<T>` handles the rest without threads; `Mutex<T>` and `RwLock<T>` take the multithreaded cases. An anti-pattern table names the usual mistakes, including a lock taken inside a hot loop and `RefCell` sprinkled everywhere.

When borrow conflicts keep returning, the skill points to neighbouring topics on data structure design and concurrency, because a repeated E0499 often means the struct itself is wrong. It is not a slash command — the description triggers it automatically, so the `SKILL.md` file has to sit in your platform's skills directory.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add actionbook/rust-skills --skill m03-mutability -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/m03-mutability/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/m03-mutability/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add actionbook/rust-skills --skill m03-mutability -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/m03-mutability/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add actionbook/rust-skills --skill m03-mutability -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/m03-mutability/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install actionbook/rust-skills m03-mutability
```

2. **Manually: put the files in place**
- File: `.github/skills/m03-mutability/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add actionbook/rust-skills --skill m03-mutability -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/actionbook/rust-skills --path skills/m03-mutability
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/m03-mutability/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add actionbook/rust-skills --skill m03-mutability -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/actionbook/rust-skills/tree/HEAD/skills/m03-mutability/SKILL.md

## When to use it
- work out an E0596 without blindly adding `mut`
- pick between `Cell`, `RefCell` and `Mutex` for a given field
- track down the borrow that makes `RefCell` panic at runtime
- untangle overlapping borrows in E0499 and E0502
- spot anti-patterns such as locking inside a hot loop

## Example prompts
- I'm getting E0502, a `&mut` while a `&` is alive. What should I restructure?
- I need to mutate a non-`Copy` field through `&self`. `RefCell`, or something else?
- My `RefCell` panics with already borrowed. How do I find the borrow that was never dropped?

## Similar
- [migrate-to-shoehorn](https://affpapa.org/en/nevibecode/skills/migrate-to-shoehorn.md) — skill · 475388 installs
- [write-swift](https://affpapa.org/en/nevibecode/skills/write-swift.md) — skill · 119300 installs
- [megacave](https://affpapa.org/en/nevibecode/skills/megacave.md) — skill · 25400 installs
- [find-docs](https://affpapa.org/en/nevibecode/skills/find-docs.md) — skill · 9400 installs
- [typescript-advanced-types](https://affpapa.org/en/nevibecode/skills/typescript-advanced-types.md) — skill · 92169 installs
- [smart-explore](https://affpapa.org/en/nevibecode/skills/smart-explore.md) — skill · 7300 installs

From the same set: [actionbook/rust-skills](https://affpapa.org/en/nevibecode/by/actionbook/rust-skills.md) — 35 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
