rust-best-practices

Apply structured Rust best practices for error handling and API design.

258|26|Updated Dec 9, 2025
One-click install
npx skills add https://github.com/majiayu000/spellbook --skill rust-best-practices-majiayu000
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-best-practices
Source: https://github.com/majiayu000/spellbook/tree/main/skills/rust-best-practices
Command: npx skills add https://github.com/majiayu000/spellbook --skill rust-best-practices-majiayu000

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Rust Best Practices Skill helps developers write safer, more idiomatic Rust by consolidating guidelines from Microsoft Pragmatic Rust and community standards into actionable patterns.

Core Features & Use Cases

  • Enforces explicit error handling patterns using thiserror for libraries and anyhow for applications.
  • Promotes API design best practices including the builder pattern and newtype wrappers.
  • Provides guidance on performance, async patterns, testing, and anti-pattern avoidance for robust Rust projects.
  • Real-world usage: refactor a crate to improve error handling, abstraction, and testability.

Quick Start

Ask the AI to align your Rust function with the Rust Best Practices guide.

Frequently Asked Questions about rust-best-practices

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

FAQPage Schema
What is the best way to handle errors in Rust libraries versus applications?

Rust error handling best practices dictate using thiserror for libraries to define custom error types and anyhow for applications to simplify dynamic error propagation. This approach ensures robust, context-rich error management across your crate boundaries.

How do I apply the builder pattern and newtype wrappers in Rust API design?

Rust API design best practices promote the builder pattern for complex object construction and newtype wrappers for type safety. These patterns prevent invalid states, improve ergonomics, and enforce clear abstraction boundaries within your codebase.

How do I refactor a Rust crate to improve testability and async performance?

Refactoring a Rust crate for testability and async performance involves applying structured best practices to avoid anti-patterns. This Skill provides guardrails to guide async patterns, testing strategies, and performance optimizations for robust projects.

Does this Rust best practices guide support avoiding common anti-patterns?

Yes, avoiding anti-patterns is a core feature of Rust best practices. It provides explicit guardrails and actionable patterns to identify and prevent common pitfalls, ensuring your code remains reliable, safe, and idiomatic throughout development.

When do I need thiserror and anyhow for robust Rust error handling?

You need thiserror and anyhow for robust Rust error handling when building libraries and applications respectively. Thiserror creates structured library errors while anyhow aggregates application-level errors, ensuring explicit and reliable error propagation.

How do I align my Rust function with idiomatic best practices?

Aligning your Rust function with best practices involves applying structured guidelines for error handling, API design, and performance. Enforcing thiserror, anyhow, builder patterns, and newtypes ensures safer, more idiomatic code.