rust-best-practices

Apply idiomatic Rust guidelines for ownership, borrowing, error handling, and testing.

Updated Nov 25, 2024
One-click install
npx skills add https://github.com/PS-Wizard/Dotfiles --skill rust-best-practices-ps-wizard
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-best-practices
Source: https://github.com/PS-Wizard/Dotfiles/tree/main/config/pi/skills/rust-best-practices
Command: npx skills add https://github.com/PS-Wizard/Dotfiles --skill rust-best-practices-ps-wizard

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Write idiomatic Rust code by codifying ownership, borrowing, error handling, performance, testing, and documentation guidelines, reducing bugs and review time.

Core Features & Use Cases

  • Borrowing vs cloning and ownership guidelines to minimize clones and avoid performance pitfalls.
  • Error handling strategies using Result, thiserror, and proper propagation to improve reliability.
  • Performance guidance including avoiding unnecessary clones, zero-cost abstractions, and linting recommendations.
  • Testing and documentation practices to create robust tests and clear public APIs, aligned with Apollo's handbook.

Quick Start

Apply these guidelines when starting or reviewing a Rust project to enforce idiomatic, safe coding practices.

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 Rust code for ownership and borrowing?

Idiomatic Rust code for ownership and borrowing minimizes unnecessary clones by applying strict guidelines, ensuring memory safety without runtime overhead. It provides specific rules for choosing borrowing over cloning to avoid common performance pitfalls.

What is the best way to handle errors and propagation in Rust?

The best way to handle errors in Rust is using Result, thiserror, and proper error propagation instead of panicking. This strategy improves code reliability by ensuring errors are explicitly handled and bubbled up to the caller cleanly.

How do I configure clippy lints for Rust performance trade-offs?

Configuring clippy lints for Rust performance involves applying linting recommendations that identify unnecessary clones and promote zero-cost abstractions. This process targets performance trade-offs early, reducing runtime overhead and review time.

What are the standard testing and documentation practices for Rust?

Standard testing and documentation practices for Rust involve creating robust tests and clear public APIs. Aligned with Apollo's handbook, these practices ensure comprehensive test coverage and well-documented public interfaces for maintainable code.

When should I refactor existing Rust code to avoid unnecessary clones?

You should refactor Rust code to avoid unnecessary clones when reviewing tasks for performance bottlenecks. Applying borrowing and ownership guidelines during refactoring eliminates abstraction violations and improves overall execution speed.