Rust Best-Practices Skill
Idiomatic refactors and clippy-clean code - an Agent Skill for Rust 1.97.0 (edition 2024) code review and cleanup.
What This Skill Does
Reviews PRs for idiomatic Rust: unnecessary clone, verbose match, missing impl Trait, poor visibility, stringly types, and clippy warnings. Produces small focused refactors with passing tests.
When to Invoke
- "Make it more idiomatic" review requests
- Clippy warning backlog cleanup
- Onboarding PRs teaching team conventions
- Pre-release polish sprint
Inputs
| Input | Why |
|---|---|
| Diff or module path | Scope limit |
| Clippy policy | -D warnings or allowlist |
| MSRV | edition 2024 features gated |
| Performance sensitivity | avoid hot-path churn |
Outputs
- Prioritized fix list (auto-fix vs manual)
- Refactored snippets
cargo fmtandclippyclean verification- Optional
#[must_use]and doc additions on public API
Guardrails
- Tests green after every refactor - no drive-by behavior change.
- Respect MSRV - no nightly-only syntax without approval.
- Public API changes need semver note - breaking renames flagged.
- Clippy allows documented -
#[allow]requires comment. - Prefer explicit over clever - readability wins tie-breaks.
Recipe
cargo fmt --all
cargo clippy --all-targets --all-features -- -D warnings
cargo test --all-features
cargo doc --no-depsWorking Example
// Before
fn get_name(user: &User) -> String {
user.name.clone()
}
// After
fn get_name(user: &User) -> &str {
&user.name
}FAQs
Apply all clippy pedantic?
Team policy decides; default to default lint level plus agreed pedantic subset.
When to allow clone?
When ownership transfer is required and profiler shows cold path.
Edition 2024 migration?
Follow workspace edition in Cargo.toml; skill respects manifest, not assumptions.
Related
Stack versions: This page was written for Rust 1.97.0 (edition 2024), Tokio 1.x, Axum 0.8, serde 1.0, sqlx 0.8, clap 4, and Polars 0.46+.