
Rust Patterns
Teach your coding agent idiomatic Rust—ownership, errors, traits, and concurrency—while you write, review, or refactor crates.
Overview
rust-patterns is an agent skill most often used in Build (also Ship review) that applies idiomatic Rust ownership, error handling, traits, and concurrency patterns.
Install
npx skills add https://github.com/affaan-m/everything-claude-code --skill rust-patternsWhat is this skill?
- Six focus areas: ownership/borrowing, Result/? with thiserror/anyhow, enums and exhaustive matches, traits/generics, Arc
- Compile-time safety patterns that avoid unnecessary clones and data races
- Library vs application error-handling split (thiserror vs anyhow)
- Safe concurrency recipes with Arc<Mutex<T>> and async/await guidance
- Explicit triggers: new code, code review, refactors, and module/crate layout
- Six key pattern areas: ownership, errors, enums, traits, concurrency, and pub/module layout
Adoption & trust: 4.3k installs on skills.sh; 210k GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You are shipping Rust fast but your agent keeps cloning buffers, fighting the borrow checker with workarounds, or mixing error types that make APIs hard to maintain.
Who is it for?
Indie builders using agents on Rust backends, CLIs, or services who want consistent, review-ready idioms without rereading the Rust book each sprint.
Skip if: Teams that only need one-off syntax help on a non-Rust stack, or greenfield specs with zero Rust code planned.
When should I use this skill?
Writing new Rust code, reviewing Rust code, refactoring existing Rust code, or designing crate structure and module layout.
What do I get? / Deliverables
Your agent proposes compile-time-safe Rust that follows standard Result/trait/concurrency patterns and clearer crate boundaries for the next review or refactor pass.
- Idiomatic Rust implementations or refactors
- Review feedback aligned to ownership and error-handling norms
Recommended Skills
Journey fit
Spans multiple journey phases - primary shelf plus alternate fits below.
Rust patterns land on the Build shelf because they guide implementation structure and crate design during active product development. Backend is the canonical subphase for systems and service-layer Rust, even when CLIs or WASM share the same ownership and error-handling rules.
Where it fits
Scaffold a new service crate with Result/? flows and domain modules before wiring HTTP handlers.
Review a PR for needless Vec clones and non-exhaustive match arms before release.
Refactor a CLI that shells out to APIs so shared logic lives behind borrowed slices instead of owned copies.
How it compares
Use instead of generic “write Rust for me” prompts when you want enforced idioms aligned to ownership and error-handling best practices, not minimal snippets that compile once.
Common Questions / FAQ
Who is rust-patterns for?
Solo and indie builders who delegate Rust implementation or review to an agent and want ownership, errors, and concurrency handled the way experienced Rustaceans expect.
When should I use rust-patterns?
During Build when authoring or refactoring crates and modules; during Ship when reviewing PRs for unnecessary clones, weak error types, or unsafe concurrency shortcuts; anytime you are restructuring a Rust workspace before adding features.
Is rust-patterns safe to install?
It is procedural guidance only—review the Security Audits panel on this Prism page and the upstream skill source before enabling it in agents with shell or network access.
SKILL.md
READMESKILL.md - Rust Patterns
# 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. ```rust // Good: Pass references when you don't need ownership fn process(data: &[u8]) -> usize { data.len() } // Good: Take ownership only when you need to store or consume fn store(data: Vec<u8>) -> Record { Record { payload: data } } // Bad: Cloning unnecessarily to avoid borrow checker fn process_bad(data: &Vec<u8>) -> usize { let cloned = data.clone(); // Wasteful — just borrow cloned.len() } ``` ### Use `Cow` for Flexible Ownership ```rust use std::borrow::Cow; fn normalize(input: &str) -> Cow<'_, str> { if input.contains(' ') { Cow::Owned(input.replace(' ', "_")) } else { Cow::Borrowed(input) // Zero-cost when no mutation needed } } ``` ## Error Handling ### Use `Result` and `?` — Never `unwrap()` in Production ```rust // Good: Propagate errors with context use anyhow::{Context, Result}; fn load_config(path: &str) -> Result<Config> { let content = std::fs::read_to_string(path) .with_context(|| format!("failed to read config from {path}"))?; let config: Config = toml::from_str(&content) .with_context(|| format!("failed to parse config from {path}"))?; Ok(config) } // Bad: Panics on error fn load_config_bad(path: &str) -> Config { let content = std::fs::read_to_string(path).unwrap(); // Panics! toml::from_str(&content).unwrap() } ``` ### Library Errors with `thiserror`, Application Errors with `anyhow` ```rust // Library code: structured, typed errors use thiserror::Error; #[derive(Debug, Error)] pub enum StorageError { #[error("record not found: {id}")] NotFound { id: String }, #[error("connection failed")] Connection(#[from] std::io::Error), #[error("invalid data: {0}")] InvalidData(String), } // Application code: flexible error handling use anyhow::{bail, Result}; fn run() -> Result<()> { let config = load_config("app.toml")?; if config.workers == 0 { bail!("worker count must be > 0"); } Ok(()) } ``` ### `Option` Combinators Over Nested Matching ```rust // Good: Combinator chain fn find_user_email(users: &[User], id: u64) -> Option<String> { users.iter() .find(|u| u.id == id) .map(|u| u.email.clone()) } // Bad: Deeply nested matching fn find_user_email_bad(users: &[User], id: u64) -> Option<String> { match users.iter().find(|u| u.id == id) { Some(user) => match &user.email { email => Some(email.clone()), }, None => None, } } ``` ## Enums and Pattern Matching ### Model States as Enums ```rust // Good: Impossible states are unrepresentable enum ConnectionState { Disconnected, Connecting { attempt: u32 }, Connected { session_id: String }, Failed { reason: String, retries: u32 }, } fn handle(state: &ConnectionState) { match state { ConnectionState::Disconnected => connect(), ConnectionState::Connecting { attempt } if *at