rust-best-practices

Standardize Rust best practices for idioms, ownership, error handling, performance, and tests.

16|9|Updated Nov 6, 2013
One-click install
npx skills add https://github.com/erikstmartin/dotfiles --skill rust-best-practices-erikstmartin
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-best-practices
Source: https://github.com/erikstmartin/dotfiles/tree/main/skills/catalog/rust/rust-best-practices
Command: npx skills add https://github.com/erikstmartin/dotfiles --skill rust-best-practices-erikstmartin

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This guide helps Rust developers write safer, more idiomatic code by clarifying ownership/borrowing, error handling, performance tips, and test/documentation practices.

Core Features & Use Cases

  • Idiomatic ownership and borrowing guidance to reduce unnecessary clones and improve function parameter choices.
  • Error handling best practices including when to use Result, thiserror, and appropriate panic avoidance.
  • Performance and testing guidance with clippy, benchmarking, and type-state patterns to ensure robust code.
  • Real-world use: refactor a Rust module to reduce allocations, improve error propagation, and add tests.

Quick Start

Begin by reviewing a small Rust module and applying ownership, error handling and testing improvements in one pass.

Frequently Asked Questions about rust-best-practices

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

FAQPage Schema
What are the best practices for Rust ownership and borrowing to reduce unnecessary clones?

Rust ownership best practices guide function parameter choices and borrowing rules to minimize unnecessary clones. Using references appropriately improves resource management across modules, reducing allocations while maintaining safety.

How do I handle error propagation in Rust using Result and thiserror?

Rust error handling best practices involve using Result for recoverable errors and thiserror for custom error types. Avoiding panics ensures robust error propagation across library and application modules.

How do I improve Rust performance with clippy and type-state patterns?

Rust performance optimization uses clippy for linting and type-state patterns to enforce compile-time checks. Benchmarking guides identify allocation reduction opportunities, ensuring robust and efficient code execution.

Does Rust testing guidance apply to both library and application codebases?

Rust testing guidance applies to both library and application codebases, covering documentation practices and test implementation. Structured rules ensure comprehensive validation across modules managing resource ownership and error handling.

What's the best way to refactor a Rust module to improve idiomatic code structure?

Refactoring Rust modules requires applying ownership, error handling, and testing improvements in one pass. Structured guidelines standardize idioms across codebases, clarifying borrowing rules and panic avoidance for safer code.

When should I avoid panics in Rust error handling?

Rust error handling practices advise avoiding panics when errors are recoverable, using Result instead. Panics should be reserved for unrecoverable states, ensuring robust error propagation and safer application behavior.