rust-best-practices

Review and write idiomatic Rust code using Apollo GraphQL's best practices handbook.

Updated Aug 20, 2026
One-click install
npx skills add https://github.com/hduoc2003/leviathan-guardian --skill rust-best-practices-hduoc2003
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: rust-best-practices
Source: https://github.com/hduoc2003/leviathan-guardian/tree/main/.agents/skills/rust-best-practices
Command: npx skills add https://github.com/hduoc2003/leviathan-guardian --skill rust-best-practices-hduoc2003

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing idiomatic Rust requires navigating ownership, borrowing, error handling, linting, and performance tradeoffs that are easy to get wrong. This Skill provides structured guidance based on Apollo GraphQL's Rust Best Practices Handbook so code reviews and new implementations follow consistent, proven conventions. ## Core Features & Use Cases - Idiomatic Code Guidance: Covers borrowing vs cloning, Copy trait usage, Option/Result handling, iterator patterns, and import organization. - Error Handling Patterns: Enforces Result-based error handling with thiserror for libraries and anyhow for binaries, avoiding unwrap/expect in production. - Linting & Performance Discipline: Provides cargo clippy workflows, key lint configurations, flamegraph profiling, and zero-cost abstraction guidance. - Testing & Documentation Standards: Covers descriptive test naming, snapshot testing with cargo insta, doc tests, and rustdoc conventions. - Use Case: When reviewing a pull request that clones data inside a loop or uses unwrap in production code, this Skill supplies the exact rule, the rationale, and the corrected pattern to suggest. ## Quick Start Review my Rust function for ownership, error handling, and clippy issues using the rust best practices guidelines.

Frequently Asked Questions about rust-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I decide between borrowing and cloning in Rust?▼

Prefer borrowing with &T unless you need an owned copy, such as for caching, Arc/Rc pointers, or APIs requiring ownership. Avoid cloning large structures like Vec or HashMap, and use &str over String and &[T] over Vec<T> in function parameters.

Should I use thiserror or anyhow for Rust error handling?▼

Use thiserror for library code where callers need precise, typed errors with #[from] conversions. Reserve anyhow for binaries where ergonomic error propagation matters more than exact error types, since anyhow erases error context callers might need.

What clippy command should I run for Rust linting?▼

Run cargo clippy --all-targets --all-features --locked -- -D warnings to check libraries, tests, benches, and examples with warnings treated as errors. Optionally add -W clippy::pedantic or -W clippy::nursery for stricter checks.

When should I use the type state pattern in Rust?▼

Use type state when you need compile-time state safety, such as preventing a client from sending messages before connecting. Avoid it for trivial states, when runtime flexibility is required, or when it leads to overly complex generic signatures.

Why is my Rust code slow and how do I profile it?▼

Most slowness comes from building without the --release flag, so always benchmark release builds. Use cargo flamegraph to visualize CPU time per function and cargo clippy -- -D clippy::perf for performance lint hints before optimizing.

When should I avoid snapshot testing with cargo insta?▼

Avoid snapshots for simple primitives, small structs, critical-path logic, and flaky or randomly generated output unless redacted. Snapshot testing works best for generated code, serialized complex data, rendered HTML, and CLI output.