Skip to content
Back to skills

Rust

ASecurity

Write idiomatic Rust avoiding ownership pitfalls, lifetime confusion, and common borrow checker battles.

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 11, 2026
documentationrustgoperformance

Security analysis

A100/100

Pro scans all 7 files and shows the line behind each finding

Scanned November 11, 2026

npx -y skills add johnalbertini14-glitch/openclaw-skills --skill rust --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Rust?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Rust
[![Security: A β€” Skills Directory](https://www.skillsdirectory.com/api/skills/johnalbertini14-glitch-rust/badge)](https://www.skillsdirectory.com/skills/johnalbertini14-glitch-rust)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
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.md3.6 KB
  • _meta.json443 B
  • advanced-traps.md2.3 KB
  • concurrency-memory.md1.8 KB
  • errors-iteration.md1.9 KB
  • ownership-borrowing.md1.7 KB
  • types-strings.md1.6 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in documentation β†’

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.