rust-patterns

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

Updated Apr 2, 2026
One-click install
npx skills add https://github.com/richardnpaul/everything-vscode-copilot --skill rust-patterns-richardnpaul
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-patterns
Source: https://github.com/richardnpaul/everything-vscode-copilot/tree/main/.github/skills/rust-patterns
Command: npx skills add https://github.com/richardnpaul/everything-vscode-copilot --skill rust-patterns-richardnpaul

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This guide helps Rust developers apply idiomatic patterns, enforce safe ownership and borrowing, robust error handling, and scalable concurrency to build safe, maintainable, high-performance software.

Core Features & Use Cases

  • Ownership and borrowing: guidelines to prevent data races and improve memory management.
  • Error handling: use Result with thiserror for libraries and anyhow for applications, plus exhaustive pattern matching to model all possible states.
  • Traits and generics: design zero-cost abstractions and flexible, reusable APIs.
  • Safe concurrency: patterns using Arc<Mutex<T>>, channels, and async/await to coordinate work safely.
  • Code organization: module layout and domain-driven structure to improve readability and testing.

Use cases include designing new crates, conducting code reviews, refactoring large Rust projects, and evolving library/application boundaries for better composability.

Quick Start

Start by applying ownership rules, prefer borrowing, and use enums and Result-based error handling in your new Rust module.

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 a Rust library versus an application?

Rust error handling in libraries should use Result with thiserror, while applications should use anyhow. This pattern ensures your crate exposes typed errors and exhaustive pattern matching, keeping application logic concise and recoverable.

What's the best way to manage safe concurrency in async Rust workloads?

Safe concurrency in Rust async workloads is managed using Arc<Mutex<T>>, channels, and async/await. These patterns coordinate work safely by enforcing ownership rules and preventing data races across threads.

How do I enforce Rust ownership and borrowing rules during code review?

Enforce Rust ownership and borrowing during code review by prioritizing borrowing over cloning, checking for exhaustive pattern matching, and ensuring minimal pub surfaces. This prevents data races and improves memory management.

When do I use traits and generics to design Rust APIs?

Use traits and generics to design Rust APIs when you need zero-cost abstractions and flexible, reusable components. This approach creates scalable interfaces without adding runtime overhead.

Does this guide support refactoring large Rust projects into domain-driven modules?

Yes, this guide supports refactoring large Rust projects by applying domain-driven module layouts and minimal pub surfaces. This organization improves readability, testing, and the evolution of library and application boundaries.

Why does exhaustive pattern matching matter when modeling states in Rust?

Exhaustive pattern matching matters in Rust because it forces the compiler to verify all possible enum states are handled. Using Result-based error handling alongside it ensures robust, maintainable software with no unhandled edge cases.