Agent skill · software engineering · affaan-m

rust-patterns

Idiomatic Rust patterns, ownership, error handling, traits, concurrency, and best practices for building safe, performant applications.

Why this skill is useful

Provides idiomatic Rust patterns and error handling techniques that the AI wouldn't reliably generate on its own.

What it needs

About 7k tokens when loaded. Last updated 2026-08-06. 238,342 stars on the source repository.

What this skill does

Rust Development Patterns Idiomatic Rust patterns and best practices for building safe, performant, and maintainable applications. When to Use Writing new Rust code Reviewing Rust code Refactoring existing Rust code Designing crate structure and module layout How It Works This skill enforces idiomatic Rust conventions across six key areas: ownership and borrowing to prevent data races at compile time, Result/? error propagation with thiserror for libraries and anyhow for applications, enums and exhaustive pattern matching to make illegal states unrepresentable, traits and generics for zero-cost abstraction, safe concurrency via Arc<Mutex<T>>, channels, and async/await, and minimal pub surfaces organized by domain. Core Principles 1. Ownership and Borrowing Rust's ownership system prevents data races and memory bugs at compile time. Use Cow for Flexible Ownership Error Handling Use Result and ? — Never unwrap() in Production Library Errors with thiserror, Application Errors with anyhow Option Combinators Over Nested Matching Enums and Pattern Matching Model States as Enums Exhaustive Matching — No Catch-All for Business Logic Traits and Generics Accept Generics, Return Concrete Types Trait Objects for Dynamic Dispatch Newtype Pattern for Type Safety Structs and Data Modeling Builder Pattern for Complex Construction Iterators and Closures Prefer Iterator Chains Over Manual Loops Use collect() with Type Annotation Concurrency Arc<Mutex<T>> for Shared Mutable State Channels for Message Passing Async with Tokio Unsafe Code When Unsafe Is Acceptable When Unsafe Is NOT Acceptable Module System and Crate Structure Organize by Domain, Not by Type Visibility — Expose Minimally Tooling Integration Essential Commands Quick Reference: Rust Idioms Idiom Description ------- ------------- Borrow, don't clone Pass &T instead of cloning unless ownership is needed Make illegal states unrepresentable Use enums to model valid states only ? over unwrap() Propagate errors, never panic in …

How to use it

Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:

@skills affaan-m/rust-patterns--05aa07

View the source on GitHub

Browse the @skills marketplace