File contents Quick Reference
Topic
File
Key Trap
Ownership & Borrowing
ownership-borrowing.md
Move semantics catch everyone
Strings & Types
types-strings.md
String vs &str, UTF-8 indexing
Errors & Iteration
errors-iteration.md
unwrap() in production, lazy iterators
Concurrency & Memory
concurrency-memory.md
Rc not Send, RefCell panics
Advanced Traps
advanced-traps.md
unsafe, macros, FFI, performance
Critical Traps (High-Frequency Failures)
Ownership — #1 Source of Compiler Errors
Variable moved after use — clone explicitly or borrow with &
for item in vec moves vec — use &vec or .iter() to borrow
String moved into function — pass &str for read-only access
Borrowing — The Borrow Checker Always Wins
Can't have &mut and & simultaneously — restructure or interior mutability
Returning reference to local fails — return owned value instead
Mutable borrow through &mut self blocks all access — split struct or RefCell
Lifetimes — When Compiler Can't Infer
'static means CAN live forever, not DOES — String is 'static capable
Struct with reference needs <'a> — struct Foo<'a> { bar: &'a str }
Function returning ref must tie to input — fn get<'a>(s: &'a str) -> &'a str
Strings — UTF-8 Surprises
s[0] doesn't compile — use .chars().nth(0) or .bytes()
.len() returns bytes, not chars — use .chars().count()
s1 + &s2 moves s1 — use format!("{}{}", s1, s2) to keep both
Error Handling — Production Code
unwrap() panics — use ? or match in production
? needs Result/Option return type — main needs -> Result<()>
expect("context") > unwrap() — shows why it panicked
Iterators — Lazy Evaluation
.iter() borrows, .into_iter() moves — choose carefully
.collect() needs type — collect::<Vec<_>>() or typed binding
Iterators are lazy — nothing runs until consumed
Concurrency — Thread Safety
Rc is NOT Send — use Arc for threads
Mutex lock returns guard — auto-unlocks on drop, don't hold across await
RwLock deadlock — reader upgrading to writer blocks forever
Memory — Smart Pointers
RefCell panics at runtime — if borrow rules violated
Box for recursive types — compiler needs known size
Avoid Rc<RefCell<T>> spaghetti — rethink ownership
Common Compiler Errors (NEW)
Error
Cause
Fix
value moved here
Used after move
Clone or borrow
cannot borrow as mutable
Already borrowed
Restructure or RefCell
missing lifetime specifier
Ambiguous reference
Add <'a>
the trait bound X is not satisfied
Missing impl
Check trait bounds
type annotations needed
Can't infer
Turbofish or explicit type
cannot move out of borrowed content
Deref moves
Clone or pattern match
Cargo Traps (NEW)
cargo update updates Cargo.lock, not Cargo.toml — manual version bump needed
Features are additive — can't disable a feature a dependency enables
[dev-dependencies] not in release binary — but in tests/examples
cargo build --release much faster — debug builds are slow intentionally
1 --- 2 name: rust 3 description: Quick Reference 4 --- 5 6 ## Quick Reference 7 8 | Topic | File | Key Trap | 9 |-------|------|----------| 10 | Ownership & Borrowing | `ownership-borrowing.md` | Move semantics catch everyone | 11 | Strings & Types | `types-strings.md` | `String` vs `&str`, UTF-8 indexing | 12 | Errors & Iteration | `errors-iteration.md` | `unwrap()` in production, lazy iterators | 13 | Concurrency & Memory | `concurrency-memory.md` | `Rc` not `Send`, `RefCell` panics | 14 | Advanced Traps | `advanced-traps.md` | unsafe, macros, FFI, performance | 15 16 --- 17 18 ## Critical Traps (High-Frequency Failures) 19 20 ### Ownership — #1 Source of Compiler Errors 21 - **Variable moved after use** — clone explicitly or borrow with `&` 22 - **`for item in vec` moves vec** — use `&vec` or `.iter()` to borrow 23 - **`String` moved into function** — pass `&str` for read-only access 24 25 ### Borrowing — The Borrow Checker Always Wins 26 - **Can't have `&mut` and `&` simultaneously** — restructure or interior mutability 27 - **Returning reference to local fails** — return owned value instead 28 - **Mutable borrow through `&mut self` blocks all access** — split struct or `RefCell` 29 30 ### Lifetimes — When Compiler Can't Infer 31 - **`'static` means CAN live forever, not DOES** — `String` is 'static capable 32 - **Struct with reference needs `<'a>`** — `struct Foo<'a> { bar: &'a str }` 33 - **Function returning ref must tie to input** — `fn get<'a>(s: &'a str) -> &'a str` 34 35 ### Strings — UTF-8 Surprises 36 - **`s[0]` doesn't compile** — use `.chars().nth(0)` or `.bytes()` 37 - **`.len()` returns bytes, not chars** — use `.chars().count()` 38 - **`s1 + &s2` moves s1** — use `format!("{}{}", s1, s2)` to keep both 39 40 ### Error Handling — Production Code 41 - **`unwrap()` panics** — use `?` or `match` in production 42 - **`?` needs `Result`/`Option` return type** — main needs `-> Result<()>` 43 - **`expect("context")` > `unwrap()`** — shows why it panicked 44 45 ### Iterators — Lazy Evaluation 46 - **`.iter()` borrows, `.into_iter()` moves** — choose carefully 47 - **`.collect()` needs type** — `collect::<Vec<_>>()` or typed binding 48 - **Iterators are lazy** — nothing runs until consumed 49 50 ### Concurrency — Thread Safety 51 - **`Rc` is NOT `Send`** — use `Arc` for threads 52 - **`Mutex` lock returns guard** — auto-unlocks on drop, don't hold across await 53 - **`RwLock` deadlock** — reader upgrading to writer blocks forever 54 55 ### Memory — Smart Pointers 56 - **`RefCell` panics at runtime** — if borrow rules violated 57 - **`Box` for recursive types** — compiler needs known size 58 - **Avoid `Rc<RefCell<T>>` spaghetti** — rethink ownership 59 60 --- 61 62 ## Common Compiler Errors (NEW) 63 64 | Error | Cause | Fix | 65 |-------|-------|-----| 66 | `value moved here` | Used after move | Clone or borrow | 67 | `cannot borrow as mutable` | Already borrowed | Restructure or RefCell | 68 | `missing lifetime specifier` | Ambiguous reference | Add `<'a>` | 69 | `the trait bound X is not satisfied` | Missing impl | Check trait bounds | 70 | `type annotations needed` | Can't infer | Turbofish or explicit type | 71 | `cannot move out of borrowed content` | Deref moves | Clone or pattern match | 72 73 --- 74 75 ## Cargo Traps (NEW) 76 77 - **`cargo update` updates Cargo.lock, not Cargo.toml** — manual version bump needed 78 - **Features are additive** — can't disable a feature a dependency enables 79 - **`[dev-dependencies]` not in release binary** — but in tests/examples 80 - **`cargo build --release` much faster** — debug builds are slow intentionally
iberi22/swal-skills/tree/main/skills/rust commit 3ff6e50cd2
Frequently asked questions How do I install the Rust skill? Run npx skillmds@latest add iberi22/rust in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
What does the Rust skill do? Quick Reference It is listed under Coding & Dev Tools on SkillMD.
Is Rust safe to use? This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
Which AI agents work with Rust? This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Is Rust free to use? Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
Who published Rust? iberi22 (@iberi22) published this skill. Their other Agent Skills are listed on their SkillMD profile.