Analyze and generate idiomatic Rust code following official style guide, std library conventions, and API design guidelines. Auto-loads when writing, reviewing, or refactoring Rust code. Use when writing Rust, reviewing Rust code, checking Rust idioms, or generating Rust scaffolding. Keywords: rust, idiomatic, ownership, borrowing, lifetime, trait, error handling, pattern matching, clippy, rustfmt, cargo
Resources
2Install
npx skillscat add wcygan/dotfiles/idiomatic-rust Install via the SkillsCat registry.
Idiomatic Rust
Analyze existing Rust code for idiomatic patterns and generate new Rust code that follows official conventions from the Rust Reference, Standard Library, Style Guide, and API Guidelines.
Analysis Mode
When reviewing Rust code, check these dimensions in order:
- Ownership & Borrowing — correct move/borrow/lifetime usage, minimal cloning
- Error Handling —
Result/?propagation, no unwrap in library code, typed errors - Naming & API Design —
as_/to_/into_conventions, getter naming, casing - Trait Implementations — derive standard traits, implement
Display/Error/From - Iterator & Closure Patterns — prefer combinators over manual loops
- Type Safety — newtypes, enums over booleans, builder pattern
- Style & Formatting — rustfmt compliance, 100-char lines, trailing commas
Present findings as:
- Issues: Non-idiomatic patterns with file:line, explanation, and fix
- Suggestions: Improvements that would make code more Rustic
- Good: Patterns already done well (brief)
References: ownership-and-borrowing
References: error-handling
References: traits-and-types
References: naming-and-api-design
References: iterators-and-closures
References: style-and-formatting
References: concurrency
Generation Mode
When writing new Rust code:
- Derive
Debugon all types; deriveClone, PartialEq, Eq, Hash, Defaultwhere appropriate - Use
thiserrorfor library errors,anyhowfor application errors - Accept borrowed params (
&str,&[T],&Path), return owned types - Use
impl Into<String>/impl AsRef<Path>for flexible APIs - Prefer
Result<T, E>returns; reservepanic!for invariant violations - Use iterators and combinators over manual indexing
- Apply
#[must_use]on functions whose return value should not be ignored - Add
#[non_exhaustive]on public enums and structs with fields - Write doc comments with examples using
?(notunwrap()) - Follow rustfmt defaults: 4-space indent, 100-char width, trailing commas in multi-line
Workflow
- Read the Rust files under review (or understand the generation request)
- Load relevant reference files for the specific patterns involved
- For analysis: identify non-idiomatic patterns, explain why, show idiomatic alternative
- For generation: write code following all conventions, run
cargo checkif available - Suggest
cargo clippyandcargo fmtas final validation