
M01 Ownership
Install this when your agent needs accurate Rust ownership, move/copy, and smart-pointer guidance while you implement systems or backend Rust code.
Overview
m01-ownership is an agent skill for the Build phase that explains Rust ownership, moves, copies, and smart pointers by comparing them to C++ and Go.
Install
npx skills add https://github.com/zhanghandong/rust-skills --skill m01-ownershipWhat is this skill?
- Side-by-side Rust vs C++ table for move, copy, and compile-time safety
- Rust vs Go memory model and explicit sharing with Arc across threads
- Smart-pointer map: Box/Rc/Arc/RefCell aligned to C++ unique_ptr and shared_ptr
- Concrete move-invalidates-source examples that prevent use-after-move bugs
Adoption & trust: 763 installs on skills.sh; 1.2k GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You are writing Rust backend code but keep hitting move errors or unsure when to use Arc, Rc, or clone compared to languages you already know.
Who is it for?
Indie builders learning Rust for backends who already know C++, Go, or similar memory models and want fast, accurate analogies at the keyboard.
Skip if: Greenfield learners who need a full Rust tutorial from scratch with no prior systems-language background.
When should I use this skill?
Borrow-checker or move/copy errors while implementing Rust backend or CLI code, or when choosing Arc/Rc/Box for shared state.
What do I get? / Deliverables
Your agent applies Rust-correct ownership and sharing patterns that compile and mirror the safety guarantees you expect from C++ or Go experience.
- Inline code fixes and patterns that respect Rust ownership rules
Recommended Skills
Journey fit
Ownership is core Rust backend literacy—you reach for it during implementation, not during idea or launch work. The content compares memory models and pointers for server-side Rust, which maps directly to the build → backend shelf.
How it compares
Reference skill for language semantics—not a test runner, linter, or project scaffold.
Common Questions / FAQ
Who is m01-ownership for?
Solo and indie developers implementing Rust services or CLIs who understand another systems language and need ownership explained in that frame.
When should I use m01-ownership?
During Build when assigning structs, passing ownership into functions, cloning vs moving, or sharing data across threads with Arc—especially right after a borrow-checker error.
Is m01-ownership safe to install?
It is documentation-style procedural knowledge with no declared tool execution; review the Security Audits panel on this Prism page before adding any skill to your agent.
SKILL.md
READMESKILL.md - M01 Ownership
# Ownership: Comparison with Other Languages ## Rust vs C++ ### Memory Management | Aspect | Rust | C++ | |--------|------|-----| | Default | Move semantics | Copy semantics (pre-C++11) | | Move | `let b = a;` (a invalidated) | `auto b = std::move(a);` (a valid but unspecified) | | Copy | `let b = a.clone();` | `auto b = a;` | | Safety | Compile-time enforcement | Runtime responsibility | ### Rust Move vs C++ Move ```rust // Rust: after move, 'a' is INVALID let a = String::from("hello"); let b = a; // a moved // println!("{}", a); // COMPILE ERROR // Equivalent in C++: // std::string a = "hello"; // std::string b = std::move(a); // std::cout << a; // UNDEFINED (compiles but buggy) ``` ### Smart Pointers | Rust | C++ | Purpose | |------|-----|---------| | `Box<T>` | `std::unique_ptr<T>` | Unique ownership | | `Rc<T>` | `std::shared_ptr<T>` | Shared ownership | | `Arc<T>` | `std::shared_ptr<T>` + atomic | Thread-safe shared | | `RefCell<T>` | (manual runtime checks) | Interior mutability | --- ## Rust vs Go ### Memory Model | Aspect | Rust | Go | |--------|------|-----| | Memory | Stack + heap, explicit | GC manages all | | Ownership | Enforced at compile-time | None (GC handles) | | Null | `Option<T>` | `nil` for pointers | | Concurrency | `Send`/`Sync` traits | Channels (less strict) | ### Sharing Data ```rust // Rust: explicit about sharing use std::sync::Arc; let data = Arc::new(vec![1, 2, 3]); let data_clone = Arc::clone(&data); std::thread::spawn(move || { println!("{:?}", data_clone); }); // Go: implicit sharing // data := []int{1, 2, 3} // go func() { // fmt.Println(data) // potential race condition // }() ``` ### Why No GC in Rust 1. **Deterministic destruction**: Resources freed exactly when scope ends 2. **Zero-cost**: No GC pauses or overhead 3. **Embeddable**: Works in OS kernels, embedded systems 4. **Predictable latency**: Critical for real-time systems --- ## Rust vs Java/C# ### Reference Semantics | Aspect | Rust | Java/C# | |--------|------|---------| | Objects | Owned by default | Reference by default | | Null | `Option<T>` | `null` (nullable) | | Immutability | Default | Must use `final`/`readonly` | | Copy | Explicit `.clone()` | Reference copy (shallow) | ### Comparison ```rust // Rust: clear ownership fn process(data: Vec<i32>) { // takes ownership // data is ours, will be freed at end } let numbers = vec![1, 2, 3]; process(numbers); // numbers is invalid here // Java: ambiguous ownership // void process(List<Integer> data) { // // Who owns data? Caller? Callee? Both? // // Can caller still use it? // } ``` --- ## Rust vs Python ### Memory Model | Aspect | Rust | Python | |--------|------|--------| | Typing | Static, compile-time | Dynamic, runtime | | Memory | Ownership-based | Reference counting + GC | | Mutability | Default immutable | Default mutable | | Performance | Native, zero-cost | Interpreted, higher overhead | ### Common Pattern Translation ```rust // Rust: borrowing iteration let items = vec!["a", "b", "c"]; for item in &items { println!("{}", item); } // items still usable // Python: iteration doesn't consume // items = ["a", "b", "c"] // for item in items: // print(item) // items still usable (different reason - ref counting) ``` --- ## Unique Rust Concepts ### Concepts Other Languages Lack 1. **Borrow Checker**: No other mainstream language has compile-time borrow checking 2. **Lifetimes**: Explicit annotation of reference validity 3. **Move by Default**: Values move, not copy 4. **No Null**: `Option<T>` instead of null pointers 5. **Affine Types**: Values can be used at most once ### Learning Curve Areas | Concept | Coming From | Key Insight | |---------|-------------|-------------| | Ownership | GC languages | Think about who "owns" data | | Borrowing | C/C++ | Like references but checked | | Lifetimes | Any | Explicit scope of validity | | Move | C++ | Move is default, not copy | --- ## Mental Model Shifts ### From