rust-best-practices
Installation
SKILL.md
Rust best practices
Use when writing or reviewing Rust crates, APIs, and application code (services, workers, CLIs).
Types and errors
- Prefer
Resultover panics for recoverable failures; usethiserror(or similar) for structured error types in libraries and APIs. - Keep public error types stable and actionable; avoid leaking internal strings in production responses.
- Use
Optiononly for true absence; don’t overload it for error cases.
Ownership and API design
- Take
&str/&[T]for read-only borrowed input; useString/Vecwhen you need to own. - Prefer
impl Traitor concrete generics in public APIs when it clarifies bounds; avoid overly clever type-level tricks without payoff. Cloneonly where cheap or necessary; preferArcfor shared immutable data across threads when profiling supports it.