Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
zhanghandong avatar

M01 Ownership

  • 822 installs
  • 1.3k repo stars
  • Updated May 24, 2026
  • zhanghandong/rust-skills

This is a copy of m01-ownership by actionbook - installs and ranking accrue to the original listing.

m01-ownership is an agent skill that teaches Rust ownership, borrowing, and move semantics by comparing them directly with C++ and Go for developers writing safe concurrent code.

About

m01-ownership is a Rust learning skill that explains ownership rules through side-by-side comparisons with C++ and Go. It contrasts Rust move semantics, where `let b = a` invalidates `a`, with C++ `std::move` behavior and Go garbage collection, and shows when explicit `clone()` is required versus implicit copies. The skill uses compile-error examples, memory-management tables, and concurrent-code scenarios so developers coming from C++ or Go can reason about borrow checker errors instead of fighting them. Reach for it when ownership, lifetimes, or move/copy behavior block progress on Rust backend or CLI code.

  • Side-by-side memory management tables contrasting Rust move semantics with C++ copy/move and Go garbage collection
  • Concrete code examples showing why moved values become invalid in Rust but compile with undefined behavior in C++
  • Smart pointer equivalence mapping: Box<T> vs unique_ptr, Rc<T>/Arc<T> vs shared_ptr, RefCell<T> vs manual checks
  • Explicit Send/Sync trait guidance for safe data sharing across threads
  • Ownership rules that prevent null dereferences and data races at compile time

M01 Ownership by the numbers

  • 822 all-time installs (skills.sh)
  • +7 installs in the week ending Jul 28, 2026 (Skillselion tracking)
  • Security screen: MEDIUM risk (skills.sh audit)
  • Data as of Jul 28, 2026 (Skillselion catalog sync)
npx skills add https://github.com/zhanghandong/rust-skills --skill m01-ownership

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs822
repo stars1.3k
Security audit3 / 3 scanners passed
Last updatedMay 24, 2026
Repositoryzhanghandong/rust-skills

How does Rust ownership differ from C++ and Go?

Quickly grasp Rust ownership rules by comparing them directly with C++ and Go while writing safe concurrent code.

Who is it for?

Developers moving from C++ or Go who need a fast, comparative explanation of Rust ownership before writing production Rust code.

Skip if: Experienced Rust developers who already internalize borrowing and only need advanced lifetime or async trait guidance.

When should I use this skill?

A developer hits borrow checker errors or asks how Rust ownership compares to C++, Go, or manual memory management.

What you get

Ownership mental model, move versus copy examples, and borrow-safe concurrent code patterns

  • ownership comparison notes
  • move and borrow examples
  • concurrent-safe coding patterns

Files

SKILL.mdMarkdownGitHub ↗

Ownership & Lifetimes

Layer 1: Language Mechanics

Core Question

Who should own this data, and for how long?

Before fixing ownership errors, understand the data's role:

  • Is it shared or exclusive?
  • Is it short-lived or long-lived?
  • Is it transformed or just read?

---

Error → Design Question

ErrorDon't Just SayAsk Instead
E0382"Clone it"Who should own this data?
E0597"Extend lifetime"Is the scope boundary correct?
E0506"End borrow first"Should mutation happen elsewhere?
E0507"Clone before move"Why are we moving from a reference?
E0515"Return owned"Should caller own the data?
E0716"Bind to variable"Why is this temporary?
E0106"Add 'a"What is the actual lifetime relationship?

---

Thinking Prompt

Before fixing an ownership error, ask:

1. What is this data's domain role?

  • Entity (unique identity) → owned
  • Value Object (interchangeable) → clone/copy OK
  • Temporary (computation result) → maybe restructure

2. Is the ownership design intentional?

  • By design → work within constraints
  • Accidental → consider redesign

3. Fix symptom or redesign?

  • If Strike 3 (3rd attempt) → escalate to Layer 2

---

Trace Up ↑

When errors persist, trace to design layer:

E0382 (moved value)
    ↑ Ask: What design choice led to this ownership pattern?
    ↑ Check: m09-domain (is this Entity or Value Object?)
    ↑ Check: domain-* (what constraints apply?)
Persistent ErrorTrace ToQuestion
E0382 repeatedm02-resourceShould use Arc/Rc for sharing?
E0597 repeatedm09-domainIs scope boundary at right place?
E0506/E0507m03-mutabilityShould use interior mutability?

---

Trace Down ↓

From design decisions to implementation:

"Data needs to be shared immutably"
    ↓ Use: Arc<T> (multi-thread) or Rc<T> (single-thread)

"Data needs exclusive ownership"
    ↓ Use: move semantics, take ownership

"Data is read-only view"
    ↓ Use: &T (immutable borrow)

---

Quick Reference

PatternOwnershipCostUse When
MoveTransferZeroCaller doesn't need data
&TBorrowZeroRead-only access
&mut TExclusive borrowZeroNeed to modify
clone()DuplicateAlloc + copyActually need a copy
Rc<T>Shared (single)Ref countSingle-thread sharing
Arc<T>Shared (multi)Atomic ref countMulti-thread sharing
Cow<T>Clone-on-writeAlloc if mutatedMight modify

Error Code Reference

ErrorCauseQuick Fix
E0382Value movedClone, reference, or redesign ownership
E0597Reference outlives ownerExtend owner scope or restructure
E0506Assign while borrowedEnd borrow before mutation
E0507Move out of borrowedClone or use reference
E0515Return local referenceReturn owned value
E0716Temporary droppedBind to variable
E0106Missing lifetimeAdd 'a annotation

---

Anti-Patterns

Anti-PatternWhy BadBetter
.clone() everywhereHides design issuesDesign ownership properly
Fight borrow checkerIncreases complexityWork with the compiler
'static for everythingRestricts flexibilityUse appropriate lifetimes
Leak with Box::leakMemory leakProper lifetime design

---

Related Skills

WhenSee
Need smart pointersm02-resource
Need interior mutabilitym03-mutability
Data is domain entitym09-domain
Learning ownership conceptsm14-mental-model

Related skills

FAQ

How is Rust move semantics different from C++?

m01-ownership shows that after `let b = a` in Rust, `a` is invalid at compile time, while C++ `std::move(a)` leaves `a` in a valid but unspecified state that can compile yet behave incorrectly.

Who should use the m01-ownership skill?

m01-ownership suits developers learning Rust ownership by comparing it with C++ and Go, especially when borrow checker errors appear while writing concurrent or systems Rust code.

Is M01 Ownership safe to install?

skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.

Rustbackendintegrations

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.