rust-best-practices

Guide idiomatic Rust code covering ownership, error handling, testing, and Clippy linting.

Updated Apr 9, 2019
One-click install
npx skills add https://github.com/Yusei-SHIRAISHI/my_dotfiles --skill rust-best-practices-yusei-shiraishi
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-best-practices
Source: https://github.com/Yusei-SHIRAISHI/my_dotfiles/tree/main/.codex/skills/rust-best-practices
Command: npx skills add https://github.com/Yusei-SHIRAISHI/my_dotfiles --skill rust-best-practices-yusei-shiraishi

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides comprehensive guidance on writing high-quality, idiomatic Rust code, covering best practices for coding styles, linting, performance, error handling, testing, and more.

Core Features & Use Cases

  • Idiomatic Rust: Learn and apply best practices for borrowing, ownership, and common Rust patterns.
  • Performance Optimization: Understand techniques to write efficient Rust code and avoid common pitfalls.
  • Robust Error Handling: Implement effective error management using Result and thiserror.
  • Testing & Linting: Integrate clippy and testing strategies for reliable code.
  • Use Case: When writing a new Rust function, reviewing existing code, or optimizing performance-critical sections, consult this Skill for guidance on idiomatic and efficient Rust development.

Quick Start

Review the provided Rust code snippet against the best practices outlined in this skill.

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 when managing ownership and borrowing?

Idiomatic Rust code prioritizes borrowing over cloning to optimize performance. You should apply ownership patterns that leverage Rust's borrow checker rules, ensuring references minimize unnecessary memory allocation while maintaining data safety.

What's the best way to handle errors in Rust using Result types?

Robust error handling in Rust uses Result types and the thiserror crate. You return Result variants instead of panicking, enabling predictable error management and precise propagation of errors through your application's call stack.

How do I use Clippy to lint and improve my Rust codebase?

Clippy lints Rust code by flagging common mistakes and non-idiomatic patterns. You run Clippy during your development workflow to automatically identify performance pitfalls and enforce community best practices across your codebase.

When should I clone data versus using a reference in Rust?

You should borrow data using references whenever possible to avoid performance overhead. Cloning is necessary when you need independent ownership of the data or when lifetimes prevent borrowing, but it introduces memory allocation costs.

Does this Rust best practices guidance apply to refactoring existing code?

Yes, the guidance addresses best practices for new code, code reviews, and refactoring. You can evaluate existing Rust snippets against these standards to optimize performance, improve error handling, and apply idiomatic patterns.