m14-mental-model
actionbook/rust-skills
Mental models and analogies for understanding Rust ownership, borrowing, and core concepts.
What is m14-mental-model?
This skill provides conceptual frameworks for learning Rust, focusing on correct mental models rather than syntax. Use it when you're confused about ownership, the borrow checker, or why Rust enforces certain rules—it explains the "why" through analogies and contrasts with other languages.
- Explains ownership, moves, and borrowing through analogies (keys, lending, remotes)
- Maps Rust concepts to mental models from Java, C++, Python, Go, and functional languages
- Visualizes memory layout and reference relationships on stack and heap
- Identifies common misconceptions and deprecated thinking patterns
- Provides thinking prompts to diagnose why the compiler rejects code
- Traces connections to related skills for deeper learning
How to install m14-mental-model
npx skills add https://github.com/actionbook/rust-skills --skill m14-mental-modelHow to use m14-mental-model
- 1.Identify the Rust concept you're confused about (ownership, borrowing, lifetimes, smart pointers)
- 2.Check the Key Mental Models table for the correct analogy and mental frame
- 3.If coming from another language, review the "Coming From Other Languages" section for the key shift
- 4.Use the Thinking Prompt to diagnose what safety guarantee is at stake
- 5.Consult the visualization diagrams to see how ownership and references work in memory
- 6.Check Common Misconceptions to avoid deprecated thinking patterns
Use cases
- Learning why Rust enforces exclusive mutable access and how it prevents data races
- Understanding the difference between ownership transfer (move) and borrowing (&T, &mut T)
- Explaining lifetime validity scopes to someone coming from a garbage-collected language
- Debugging borrow checker errors by understanding the safety guarantee being enforced
- Transitioning mental models when switching from C++, Java, Python, or Go to Rust
- Developers new to Rust learning core concepts
- Programmers transitioning from garbage-collected or manual-memory languages
- Anyone confused by borrow checker errors and needing conceptual clarity
- Educators or mentors explaining Rust ownership to others
m14-mental-model FAQ
Ownership is like having a unique key to a house (only one owner, full control). Borrowing is lending that key temporarily: immutable borrowing (&T) is like lending a book to read, mutable borrowing (&mut T) is like giving exclusive editing rights to a document.
Rust prevents data races by enforcing exclusive access: only one writer at a time. Multiple mutable references would allow aliased mutation (two parts of code changing the same data simultaneously), violating memory safety.
A move transfers ownership from one variable to another. The original variable becomes invalid because the unique key has been handed over. This is not a copy—it's a transfer of responsibility.
Lifetimes are not GC. They're compile-time validity scopes that tell the compiler how long a reference is safe to use. The compiler enforces these rules statically, so no runtime overhead.
Box<T> is for single ownership on the heap. Rc<T> is for shared ownership within a single thread (like multiple remotes for one TV). Arc<T> is for shared ownership across threads safely.
Full instructions (SKILL.md)
Source of truth, from actionbook/rust-skills.
name: m14-mental-model description: "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" user-invocable: false
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<T> | Heap pointer | Remote control to TV |
Rc<T> | Shared ownership | Multiple remotes, last turns off |
Arc<T> | 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:
-
What's the ownership model?
- Who owns this data?
- How long does it live?
- Who can access it?
-
What guarantee is Rust providing?
- No data races
- No dangling pointers
- No use-after-free
-
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 |
Related skills
More from actionbook/rust-skills and the wider catalog.

m15-anti-pattern
Identify and refactor Rust code anti-patterns during review.

meta-cognition-parallel
Three-layer parallel meta-cognition analysis for Rust questions—language mechanics, design choices, and domain constraints.

rust-call-graph
Visualize Rust function call graphs and trace caller/callee relationships using LSP.

rust-code-navigator
Navigate Rust code with LSP: go to definition, find references, and explore symbols efficiently.

rust-daily
Fetch Rust community news and updates filtered by time range (daily, weekly, or monthly).

rust-deps-visualizer
Visualize Rust project dependencies as ASCII art trees with optional feature flags.