Learn idiomatic Rust patterns, ownership, concurrency, and robust error handling practices.
Copy the install command and let the AI configure it · recommended for beginners
Please install the "rust-patterns" skill from askskill: 1. Download https://raw.githubusercontent.com/affaan-m/ECC/main/skills/rust-patterns/SKILL.md 2. Save it as ~/.claude/skills/rust-patterns/SKILL.md 3. Reload skills and tell me it's ready
Review this Rust code’s error handling, identify non-idiomatic parts, and suggest a clearer, safer refactor using Result, thiserror, or anyhow, explaining the reason for each change.
A guided refactor with explanations covering error type design, propagation, and maintainability improvements.
I’m building a Rust concurrency module. Recommend suitable concurrency patterns, compare where Arc, Mutex, RwLock, mpsc, and tokio tasks fit best, and provide an example structure.
A concurrency design recommendation with tradeoff analysis and a thread-safe example code structure.
Analyze the trait, lifetime, and ownership usage in this Rust API design, point out what could be more idiomatic, and suggest changes to improve performance and readability.
An API design review covering trait abstractions, borrowing strategy, and performance optimization suggestions.
Idiomatic Rust patterns and best practices for building safe, performant, and maintainable applications.
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.
Rust's ownership system prevents data races and memory bugs at compile time.
// 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()
}
Cow for Flexible Ownershipuse 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
}
}
Result and ? — Never unwrap() in Production// 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()
}
thiserror, Application Errors with anyhow// 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// 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,
}
}
// 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 *attempt > 3 => abort(),
ConnectionState::Connecting { .. } => wait(),
ConnectionState::Connected { session_id } => use_session(session_id),
…
Review Flutter and Dart code for architecture, performance, accessibility, and security.
Get expert guidance for building and maintaining apps with the tinystruct Java framework.
Design robust Playwright E2E tests, CI pipelines, and flaky test mitigation.
Write, run, and improve Perl automated tests with coverage analysis.
Get PostgreSQL best practices for optimization, schema design, indexing, and security.
Design, configure, and test Celery async and scheduled jobs in Django.
Learn idiomatic Go patterns and best practices for robust, maintainable applications.
Apply idiomatic Kotlin patterns to build robust, efficient, maintainable applications.
Learn Rust testing patterns and TDD to improve code quality and reliability.
Get idiomatic C# and .NET guidance for architecture, async, and dependency injection.
Learn Pythonic patterns, type hints, and best practices for maintainable code.
Apply modern Perl 5.36+ idioms and best practices for maintainable applications.