rust-best-practices

Review Rust code for ownership, error handling, and performance anti-patterns.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/aster-void/dotfiles --skill rust-best-practices
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-best-practices
Source: https://github.com/aster-void/dotfiles/tree/main/modules/home/profile-dev/programs/claude-code/skills/rust-best-practices
Command: npx skills add https://github.com/aster-void/dotfiles --skill rust-best-practices

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill ensures that Rust code adheres to best practices, preventing common pitfalls related to ownership, error handling, and performance. It helps developers write cleaner, safer, and more efficient Rust, reducing debugging time and improving overall code quality and maintainability.

Core Features & Use Cases

  • Idiomatic Error Handling: Guides on using thiserror for libraries and anyhow for applications, avoiding generic Box<dyn Error> for clearer error types.
  • Ownership & Borrowing Patterns: Provides solutions for common ownership "gotchas" like partial and overly broad borrows, ensuring efficient and safe memory management.
  • Performance & Security: Offers advice on profiling, inlining tiny functions, enabling checked arithmetic, validating external input, and using cargo-audit for dependency vulnerability checks.
  • Use Case: Review an existing Rust codebase to identify and refactor anti-patterns, ensuring it follows modern Rust idioms for better maintainability, security, and performance.

Quick Start

Review the attached Rust code for common anti-patterns related to ownership and error handling, and suggest improvements to make it more idiomatic.

Frequently Asked Questions about rust-best-practices

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

FAQPage Schema
How do I write idiomatic error handling in Rust libraries and applications?

Idiomatic error handling uses `thiserror` for libraries to define custom error types and `anyhow` at application boundaries for flexible error propagation. Avoid generic `Box<dyn Error>` to preserve type information and enable clearer error handling paths.

What are common ownership and borrowing gotchas in Rust code?

Common ownership pitfalls include partial borrows that prevent later use of the full value and overly broad borrow scopes that extend past their actual need. Review code for unnecessary lifetime extensions and ensure borrows are scoped as tightly as possible for performance and safety.

How do I review Rust code for anti-patterns and performance issues?

Code review for anti-patterns focuses on ownership efficiency, error handling consistency, and type system idioms. Check for missed inlining opportunities in tiny functions, improper use of collections, and security gaps like unvalidated external input or unchecked arithmetic.

What Rust crates and patterns should I use for production code?

Production Rust typically uses `serde` for serialization, `tokio` for async runtime, `axum` for web frameworks, `clap` for CLI argument parsing, and `reqwest` for HTTP clients. Apply builder patterns, newtype patterns, and prefer `&str` and `&[T]` over owned types where possible.

How do I check for security vulnerabilities and enable safety checks in Rust?

Run `cargo-audit` to scan dependencies for known vulnerabilities and validate all external input before use. Enable checked arithmetic in debug builds and consider overflow checks in performance-sensitive code to catch numeric bugs early.

When should I use enums instead of booleans in Rust?

Use enums over boolean flags when state has more than two meaningful outcomes or when the intent is clearer with named variants. Enums prevent invalid state combinations and make function signatures self-documenting, improving maintainability and reducing logic errors.