Back to skills
SKILL.md
Rust
ASecurityWrite idiomatic Rust avoiding ownership pitfalls, lifetime confusion, and common borrow checker battles.
- 2 stars
- 0 votes
- 0 copies
- 0 views
- Added November 11, 2026
Security analysis
100/100Pro scans all 7 files and shows the line behind each finding
npx -y skills add johnalbertini14-glitch/openclaw-skills --skill rust --agent claude-codeAre you the author of Rust?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/johnalbertini14-glitch-rust)---
name: Rust
slug: rust
version: 1.0.1
description: Write idiomatic Rust avoiding ownership pitfalls, lifetime confusion, and common borrow checker battles.
metadata: {"clawdbot":{"emoji":"π¦","requires":{"bins":["rustc","cargo"]},"os":["linux","darwin","win32"]}}
---
## 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
Files in this skill
- SKILL.md
- _meta.json
- advanced-traps.md
- concurrency-memory.md
- errors-iteration.md
- ownership-borrowing.md
- types-strings.md
Attribution
Related skills
View all in documentation βComments
Loading commentsβ¦
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.