Rust Best Practices

Standardize Rust code authoring and review with clippy-informed quality gates.

1|1|Updated Apr 20, 2026
One-click install
npx skills add https://github.com/svssdeva/agentic-skills --skill rust-best-practices-svssdeva
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Rust Best Practices
Source: https://github.com/svssdeva/agentic-skills/tree/main/rust/rust-best-practices
Command: npx skills add https://github.com/svssdeva/agentic-skills --skill rust-best-practices-svssdeva

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Helps you consistently write and review Rust code with strong idioms, reliable error handling, and performance-aware practices instead of ad-hoc patterns.

Core Features & Use Cases

  • Ownership and borrowing guidance: Chooses references vs cloning, prefers efficient parameter types (like &str/&[T]), and recommends Cow when ownership is ambiguous.
  • Production-safe error handling: Encourages Result over panic!, bans unwrap/expect outside tests, and recommends thiserror for libraries and anyhow for binaries.
  • Performance mindset and lint discipline: Promotes --release benchmarking, targeted cargo clippy runs, and specific lint awareness (e.g., redundant_clone, needless_collect).
  • Maintainable code and testing practices: Recommends descriptive test naming, doc tests, and snapshot testing where appropriate, supported by documentation and comment standards.

Quick Start

Ask your AI to review the Rust module for ownership, error handling, clippy/lint risks, and performance pitfalls using this best-practices checklist.

Frequently Asked Questions about Rust Best Practices

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

FAQPage Schema
How do I handle Rust errors without using unwrap and expect?

Rust error handling should use Result-based propagation instead of unwrap or expect to prevent panics. Use thiserror for libraries and anyhow for binaries to ensure production-safe error management.

What's the best way to choose between borrowing and cloning in Rust?

Rust ownership guidance prefers references over cloning, using efficient parameter types like &str or &[T]. Choose Cow when ownership is ambiguous to balance performance and safety.

How do I use clippy lints to improve Rust performance?

Run cargo clippy with --release benchmarking to catch performance pitfalls. Target specific lints like redundant_clone and needless_collect to identify and remove inefficient ownership patterns.

When do I need thiserror vs anyhow for Rust error handling?

Use thiserror for libraries to define custom error types and anyhow for binaries to handle dynamic errors. This distinction ensures appropriate Result-based error propagation across your Rust project.

What testing practices should I follow for Rust modules?

Rust testing practices recommend descriptive test naming, doc tests, and snapshot testing where appropriate. These standards ensure maintainable code and validate module behavior effectively.

How do I review Rust code for ownership and performance pitfalls?

Review Rust code by checking ownership handling, error management, clippy lint risks, and performance bottlenecks. Apply quality gates to reduce unsafe patterns and inefficient borrowing before merging.