🎯

m14-mental-model

🎯Skill

from actionbook/rust-skills

VibeIndex|
What it does

Helps developers build intuitive mental models for understanding Rust's ownership, borrowing, and memory safety concepts through clear analogies and systematic thinking.

πŸ“¦

Part of

actionbook/rust-skills(35 items)

m14-mental-model

Installation

Quick InstallInstall with npx
npx skills add ZhangHanDong/rust-skills
CargoRun with Cargo (Rust)
cargo install cowork
git cloneClone repository
git clone https://github.com/ZhangHanDong/rust-skills.git
Add MarketplaceAdd marketplace to Claude Code
/plugin marketplace add ZhangHanDong/rust-skills
πŸ“– Extracted from docs: actionbook/rust-skills
15Installs
-
AddedFeb 4, 2026

Skill Details

SKILL.md

"Use when learning Rust concepts. Keywords: mental model, how to think about ownership, understanding borrow checker, visualizing memory layout, analogy, misconception, explaining ownership, why does Rust, help me understand, confused about, learning Rust, explain like I'm, ELI5, intuition for, coming from Java, coming from Python, εΏƒζ™Ίζ¨‘εž‹, ε¦‚δ½•η†θ§£ζ‰€ζœ‰ζƒ, ε­¦δΉ  Rust, Rust ε…₯ι—¨, δΈΊδ»€δΉˆ Rust"

Overview

# Mental Models

> Layer 2: Design Choices

Core Question

What's the right way to think about this Rust concept?

When learning or explaining Rust:

  • What's the correct mental model?
  • What misconceptions should be avoided?
  • What analogies help understanding?

---

Key Mental Models

| Concept | Mental Model | Analogy |

|---------|--------------|---------|

| Ownership | Unique key | Only one person has the house key |

| Move | Key handover | Giving away your key |

| &T | Lending for reading | Lending a book |

| &mut T | Exclusive editing | Only you can edit the doc |

| Lifetime 'a | Valid scope | "Ticket valid until..." |

| Box | Heap pointer | Remote control to TV |

| Rc | Shared ownership | Multiple remotes, last turns off |

| Arc | Thread-safe Rc | Remotes from any room |

---

Coming From Other Languages

| From | Key Shift |

|------|-----------|

| Java/C# | Values are owned, not references by default |

| C/C++ | Compiler enforces safety rules |

| Python/Go | No GC, deterministic destruction |

| Functional | Mutability is safe via ownership |

| JavaScript | No null, use Option instead |

---

Thinking Prompt

When confused about Rust:

  1. What's the ownership model?

- Who owns this data?

- How long does it live?

- Who can access it?

  1. What guarantee is Rust providing?

- No data races

- No dangling pointers

- No use-after-free

  1. What's the compiler telling me?

- Error = violation of safety rule

- Solution = work with the rules

---

Trace Up ↑

To design understanding (Layer 2):

```

"Why can't I do X in Rust?"

↑ Ask: What safety guarantee would be violated?

↑ Check: m01-m07 for the rule being enforced

↑ Ask: What's the intended design pattern?

```

---

Trace Down ↓

To implementation (Layer 1):

```

"I understand the concept, now how do I implement?"

↓ m01-ownership: Ownership patterns

↓ m02-resource: Smart pointer choice

↓ m07-concurrency: Thread safety

```

---

Common Misconceptions

| Error | Wrong Model | Correct Model |

|-------|-------------|---------------|

| E0382 use after move | GC cleans up | Ownership = unique key transfer |

| E0502 borrow conflict | Multiple writers OK | Only one writer at a time |

| E0499 multiple mut borrows | Aliased mutation | Exclusive access for mutation |

| E0106 missing lifetime | Ignoring scope | References have validity scope |

| E0507 cannot move from &T | Implicit clone | References don't own data |

Deprecated Thinking

| Deprecated | Better |

|------------|--------|

| "Rust is like C++" | Different ownership model |

| "Lifetimes are GC" | Compile-time validity scope |

| "Clone solves everything" | Restructure ownership |

| "Fight the borrow checker" | Work with the compiler |

| "unsafe to avoid rules" | Understand safe patterns first |

---

Ownership Visualization

```

Stack Heap

+----------------+ +----------------+

| main() | | |

| s1 ─────────────────────> β”‚ "hello" |

| | | |

| fn takes(s) { | | |

| s2 (moved) ─────────────> β”‚ "hello" |

| } | | (s1 invalid) |

+----------------+ +----------------+

After move: s1 is no longer valid

```

Reference Visualization

```

+----------------+

| data: String |────────────> "hello"

+----------------+

↑

β”‚ &data (immutable borrow)

β”‚

+------+------+

| reader1 reader2 (multiple OK)

+------+------+

+----------------+

| data: String |────────────> "hello"

+----------------+

↑

β”‚ &mut data (mutable borrow)

β”‚

+------+

| writer (only one)

+------+

```

---

Learning Path

| Stage | Focus | Skills |

|-------|-------|--------|

| Beginner | Ownership basics | m01-ownership, m14-mental-model |

| Intermediate | Smart pointers, error handling | m02, m06 |

| Advanced | Concurrency, unsafe | m07, unsafe-checker |

| Expert | Design patterns | m09-m15, domain-* |

---

Related Skills

| When | See |

|------|-----|

| Ownership errors | m01-ownership |

| Smart pointers | m02-resource |

| Concurrency | m07-concurrency |

| Anti-patterns | m15-anti-pattern |

More from this repository10

πŸͺ
actionbook-rust-skillsπŸͺMarketplace

Comprehensive Rust development assistant with meta-question routing, coding guidelines, version queries, and ecosystem support

🎯
coding-guidelines🎯Skill

Provides comprehensive Rust coding guidelines covering naming conventions, best practices, error handling, memory management, concurrency, and code style recommendations.

🎯
rust-refactor-helper🎯Skill

Performs safe Rust refactoring by analyzing symbol references, dependencies, and potential impacts using Language Server Protocol (LSP) operations.

🎯
m09-domain🎯Skill

Guides domain modeling in Rust by helping identify entities, value objects, aggregates, and their ownership patterns with domain-driven design principles.

🎯
m05-type-driven🎯Skill

Enforces compile-time type safety by preventing invalid states through type-level design techniques like newtypes, type states, and phantom types.

🎯
rust-learner🎯Skill

Retrieves and provides comprehensive Rust and crate information, including versions, features, documentation, and changelogs from authoritative sources.

🎯
m02-resource🎯Skill

Guides developers in selecting the right smart pointer and resource management strategy based on ownership, thread safety, and design constraints.

🎯
m11-ecosystem🎯Skill

Guides Rust developers in selecting, integrating, and managing ecosystem dependencies with best practices and strategic decision-making.

🎯
rust-trait-explorer🎯Skill

Explores Rust trait implementations, revealing which types implement specific traits and their implementation details using LSP.

🎯
rust-call-graph🎯Skill

Generates and visualizes Rust function call graphs using LSP, revealing function relationships and call hierarchies.