PluginBench
Skill
Pass
Audit score 90

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-model
Claude Code
Cursor
Windsurf
Cline

How to use m14-mental-model

  1. 1.Identify the Rust concept you're confused about (ownership, borrowing, lifetimes, smart pointers)
  2. 2.Check the Key Mental Models table for the correct analogy and mental frame
  3. 3.If coming from another language, review the "Coming From Other Languages" section for the key shift
  4. 4.Use the Thinking Prompt to diagnose what safety guarantee is at stake
  5. 5.Consult the visualization diagrams to see how ownership and references work in memory
  6. 6.Check Common Misconceptions to avoid deprecated thinking patterns

Use cases

Good for
  • 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
Who it's for
  • 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

What's the difference between ownership and borrowing?

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.

Why can't I have multiple mutable references?

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.

What does 'move' mean in Rust?

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.

How do lifetimes relate to garbage collection?

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.

How do I choose between Box, Rc, and Arc?

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

ConceptMental ModelAnalogy
OwnershipUnique keyOnly one person has the house key
MoveKey handoverGiving away your key
&TLending for readingLending a book
&mut TExclusive editingOnly you can edit the doc
Lifetime 'aValid scope"Ticket valid until..."
Box<T>Heap pointerRemote control to TV
Rc<T>Shared ownershipMultiple remotes, last turns off
Arc<T>Thread-safe RcRemotes from any room

Coming From Other Languages

FromKey Shift
Java/C#Values are owned, not references by default
C/C++Compiler enforces safety rules
Python/GoNo GC, deterministic destruction
FunctionalMutability is safe via ownership
JavaScriptNo 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?
  2. What guarantee is Rust providing?

    • No data races
    • No dangling pointers
    • No use-after-free
  3. 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

ErrorWrong ModelCorrect Model
E0382 use after moveGC cleans upOwnership = unique key transfer
E0502 borrow conflictMultiple writers OKOnly one writer at a time
E0499 multiple mut borrowsAliased mutationExclusive access for mutation
E0106 missing lifetimeIgnoring scopeReferences have validity scope
E0507 cannot move from &TImplicit cloneReferences don't own data

Deprecated Thinking

DeprecatedBetter
"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

StageFocusSkills
BeginnerOwnership basicsm01-ownership, m14-mental-model
IntermediateSmart pointers, error handlingm02, m06
AdvancedConcurrency, unsafem07, unsafe-checker
ExpertDesign patternsm09-m15, domain-*

Related Skills

WhenSee
Ownership errorsm01-ownership
Smart pointersm02-resource
Concurrencym07-concurrency
Anti-patternsm15-anti-pattern