rust-patterns

Enforce idiomatic Rust patterns for ownership, error handling, and concurrency.

1|Updated Jan 30, 2021
One-click install
npx skills add https://github.com/fideguch/my_dotfiles --skill rust-patterns-fideguch
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-patterns
Source: https://github.com/fideguch/my_dotfiles/tree/main/claude/skills/rust-patterns
Command: npx skills add https://github.com/fideguch/my_dotfiles --skill rust-patterns-fideguch

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Idiomatic Rust patterns help developers write safe, maintainable, and efficient code by aligning ownership, error handling, and concurrency with established best practices.

Core Features & Use Cases

  • Ownership and borrowing rules to prevent data races at compile time.
  • Structured error handling with thiserror for libraries and anyhow for applications, plus exhaustive enums for robust state modeling.
  • Traits, generics, and the Newtype pattern to enable zero-cost abstractions and safer APIs.
  • Safe concurrency patterns using Arc<Mutex<T>>, channels, and async/await.
  • Clear module structure and minimal pub surfaces to enforce clean boundaries.

Quick Start

Read and apply these patterns to your Rust codebase to improve safety and performance.

Frequently Asked Questions about rust-patterns

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

FAQPage Schema
What's the best way to handle Rust ownership and borrowing to prevent data races?

Idiomatic Rust ownership and borrowing rules prevent data races at compile time by enforcing strict reference constraints. Applying these patterns during code reviews and refactoring ensures safe, efficient memory management without runtime overhead.

How do I choose between thiserror and anyhow for Rust error handling?

Use thiserror for structured library error enums and anyhow for application-level error aggregation. Enforcing these error handling semantics ensures robust state modeling and consistent error propagation across Rust codebases.

When do I need Arc<Mutex<T>> and channels for safe concurrency in Rust?

Use Arc<Mutex<T>> and channels for safe Rust concurrency when sharing mutable state across threads or passing messages asynchronously. These idiomatic patterns enforce thread safety and align with async/await best practices.

How do I use traits and generics for zero-cost abstractions in Rust?

Use Rust traits and generics to enable zero-cost abstractions by defining shared behavior without runtime overhead. Combining them with the Newtype pattern creates safer APIs and cleaner module boundaries for crate design.

Does applying idiomatic Rust patterns require a specific crate structure?

Applying idiomatic Rust patterns requires a clear module structure with minimal pub surfaces to enforce clean boundaries. Restricting public visibility ensures safe ownership, controlled error handling semantics, and robust crate design.