# Rust

> Use when: write or review idiomatic Rust with sound ownership, error handling, and zero-cost abstractions.

- Skill: `kimtth/rust` (Agent Skill)
- Install (CLI): `npx skillmds@latest add kimtth/rust`
- Raw SKILL.md: https://api.skillmd.com/api/skills/kimtth/rust/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: kimtth (https://skillmd.com/u/kimtth)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/kimtth/rust

---


Goal: safe, idiomatic Rust that the borrow checker and tests both accept.

Use for:
- new crates, modules, or performance-sensitive code
- reviewing ownership, lifetimes, and error handling
- replacing unwrap-heavy or clone-heavy code

Workflow:
1. Model data with enums and structs; make invalid states unrepresentable.
2. Return Result with a typed error; reserve panics for bugs.
3. Borrow by default; clone only with a reason.
4. Use iterators and combinators over manual index loops.
5. Encode invariants in the type system, not runtime checks.
6. Verify with cargo test, clippy, and cargo fmt.

Idioms:
- ? operator for error propagation
- Option/Result combinators (map, and_then, ok_or)
- thiserror for libraries, anyhow for applications
- traits for shared behavior; generics with bounds
- prefer &str/&[T] params over owned types

Rules:
- avoid unwrap/expect outside tests and proven invariants
- do not reach for unsafe without a documented justification
- let the borrow checker guide design, not fight it
- keep clippy clean; warnings are signal

