rust-patterns

Enforce ownership, error handling, and concurrency patterns in Rust code.

16|3|Updated Mar 12, 2026
One-click install
npx skills add https://github.com/sehoon787/my-claude --skill rust-patterns-sehoon787
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-patterns
Source: https://github.com/sehoon787/my-claude/tree/main/skills/ecc/rust-patterns
Command: npx skills add https://github.com/sehoon787/my-claude --skill rust-patterns-sehoon787

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Idiomatic Rust patterns and best practices help developers write safe, maintainable, and high-performance Rust code by guiding ownership, error handling, concurrency, and module design.

Core Features & Use Cases

  • Enforces clear ownership and borrowing to prevent data races at compile time.
  • Demonstrates robust error handling with Result/?, and commonly used crates like thiserror and anyhow.
  • Promotes safe concurrency via Arc<Mutex<T>>, channels, and async/await patterns.
  • Guides module structure, traits, and generics for zero-cost abstractions and clean APIs.
  • Use Case: refactor legacy Rust code to idiomatic patterns in a mid-sized project.

Quick Start

Read this guide and start applying the idiomatic Rust patterns to a current Rust codebase.

Frequently Asked Questions about rust-patterns

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

FAQPage Schema
How do I handle errors in Rust using Result and the ? operator?

Idiomatic Rust error handling uses the Result type with the ? operator for safe propagation. Libraries use thiserror for custom error enums, while applications use anyhow for flexible error handling.

How do I share data across threads safely in Rust?

Safe Rust concurrency is achieved using Arc<Mutex<T>> to share mutable data across threads. Channels and async/await patterns also provide data race-free concurrent execution guaranteed at compile time.

What are the best practices for structuring Rust modules and traits?

Idiomatic Rust design uses traits and generics for zero-cost abstractions and clean APIs. Minimal visibility with pub(crate) and modular structure guide maintainable project organization and high-performance code.

How do I refactor legacy Rust code to follow ownership and borrowing rules?

Refactoring legacy Rust code to idiomatic patterns enforces clear ownership and borrowing rules to prevent data races at compile time. This involves applying explicit ownership rules and exhaustive pattern matching.

When should I use thiserror vs anyhow for Rust error handling?

Use thiserror to define structured, exhaustive error enums in Rust libraries, and use anyhow for flexible application-level error handling. Both enforce Result-based error propagation to maintain safe code.