1---2name: modbender-skill-library-mcp-rust3description: ---4---5---6name: Rust7slug: rust8version: 1.0.19description: Write idiomatic Rust avoiding ownership pitfalls, lifetime confusion, and common borrow checker battles.10metadata: {"clawdbot":{"emoji":"🦀","requires":{"bins":["rustc","cargo"]},"os":["linux","darwin","win32"]}}11---1213## Quick Reference1415| Topic | File | Key Trap |16|-------|------|----------|17| Ownership & Borrowing | `ownership-borrowing.md` | Move semantics catch everyone |18| Strings & Types | `types-strings.md` | `String` vs `&str`, UTF-8 indexing |19| Errors & Iteration | `errors-iteration.md` | `unwrap()` in production, lazy iterators |20| Concurrency & Memory | `concurrency-memory.md` | `Rc` not `Send`, `RefCell` panics |21| Advanced Traps | `advanced-traps.md` | unsafe, macros, FFI, performance |2223---2425## Critical Traps (High-Frequency Failures)2627### Ownership — #1 Source of Compiler Errors28- **Variable moved after use** — clone explicitly or borrow with `&`29- **`for item in vec` moves vec** — use `&vec` or `.iter()` to borrow30- **`String` moved into function** — pass `&str` for read-only access3132### Borrowing — The Borrow Checker Always Wins33- **Can't have `&mut` and `&` simultaneously** — restructure or interior mutability34- **Returning reference to local fails** — return owned value instead35- **Mutable borrow through `&mut self` blocks all access** — split struct or `RefCell`3637### Lifetimes — When Compiler Can't Infer38- **`'static` means CAN live forever, not DOES** — `String` is 'static capable39- **Struct with reference needs `<'a>`** — `struct Foo<'a> { bar: &'a str }`40- **Function returning ref must tie to input** — `fn get<'a>(s: &'a str) -> &'a str`4142### Strings — UTF-8 Surprises43- **`s[0]` doesn't compile** — use `.chars().nth(0)` or `.bytes()`44- **`.len()` returns bytes, not chars** — use `.chars().count()`45- **`s1 + &s2` moves s1** — use `format!("{}{}", s1, s2)` to keep both4647### Error Handling — Production Code48- **`unwrap()` panics** — use `?` or `match` in production49- **`?` needs `Result`/`Option` return type** — main needs `-> Result<()>`50- **`expect("context")` > `unwrap()`** — shows why it panicked5152### Iterators — Lazy Evaluation53- **`.iter()` borrows, `.into_iter()` moves** — choose carefully54- **`.collect()` needs type** — `collect::<Vec<_>>()` or typed binding55- **Iterators are lazy** — nothing runs until consumed5657### Concurrency — Thread Safety58- **`Rc` is NOT `Send`** — use `Arc` for threads59- **`Mutex` lock returns guard** — auto-unlocks on drop, don't hold across await60- **`RwLock` deadlock** — reader upgrading to writer blocks forever6162### Memory — Smart Pointers63- **`RefCell` panics at runtime** — if borrow rules violated64- **`Box` for recursive types** — compiler needs known size65- **Avoid `Rc<RefCell<T>>` spaghetti** — rethink ownership6667---6869## Common Compiler Errors (NEW)7071| Error | Cause | Fix |72|-------|-------|-----|73| `value moved here` | Used after move | Clone or borrow |74| `cannot borrow as mutable` | Already borrowed | Restructure or RefCell |75| `missing lifetime specifier` | Ambiguous reference | Add `<'a>` |76| `the trait bound X is not satisfied` | Missing impl | Check trait bounds |77| `type annotations needed` | Can't infer | Turbofish or explicit type |78| `cannot move out of borrowed content` | Deref moves | Clone or pattern match |7980---8182## Cargo Traps (NEW)8384- **`cargo update` updates Cargo.lock, not Cargo.toml** — manual version bump needed85- **Features are additive** — can't disable a feature a dependency enables86- **`[dev-dependencies]` not in release binary** — but in tests/examples87- **`cargo build --release` much faster** — debug builds are slow intentionally8889---90> Source: [modbender/skill-library-mcp](https://github.com/modbender/skill-library-mcp) — distributed by [TomeVault](https://tomevault.io).91<!-- tomevault:4.0:skill_md:2026-06-16 -->