ecc-rust-patterns

Applies idiomatic Rust patterns for ownership, error handling, concurrency, and module design.

Updated Apr 18, 2025
One-click install
npx skills add https://github.com/adriancodes/dotfiles --skill ecc-rust-patterns-adriancodes
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: ecc-rust-patterns
Source: https://github.com/adriancodes/dotfiles/tree/main/dot_agents/skills/ecc-rust-patterns
Command: npx skills add https://github.com/adriancodes/dotfiles --skill ecc-rust-patterns-adriancodes

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing and reviewing Rust code often leads to common mistakes like unnecessary cloning, unwrap() panics, wildcard match arms, and blocking calls in async contexts. This Skill provides a structured reference of idiomatic Rust patterns so code follows ownership, error handling, and concurrency best practices from the start. ## Core Features & Use Cases - Ownership and Error Handling Patterns: Enforces borrowing over cloning, Result/? propagation, thiserror for libraries, and anyhow for applications. - Type-Safe Design Guidance: Covers enums for state modeling, exhaustive matching, newtype wrappers, builder patterns, and minimal pub visibility. - Concurrency and Async Patterns: Provides Arc<Mutex<T>>, bounded channels, and Tokio async patterns with timeouts and task spawning. - Use Case: When reviewing a Rust pull request that uses unwrap() in library code and clones data to satisfy the borrow checker, use this Skill to rewrite it with typed errors and proper borrowing. ## Quick Start Review my Rust module for idiomatic patterns and suggest fixes for error handling and ownership issues.

Frequently Asked Questions about ecc-rust-patterns

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

FAQPage Schema
How do I handle errors in Rust without using unwrap?▼

Propagate errors with the ? operator and Result return types instead of unwrap. Use thiserror to define typed error enums in libraries and anyhow with context() for flexible error handling in application code.

When should I use thiserror vs anyhow in Rust?▼

Use thiserror for library code where callers need structured, matchable error types. Use anyhow for application code where you need flexible error propagation with added context and do not expose error types to consumers.

How do I share mutable state across threads in Rust?▼

Wrap the state in Arc<Mutex<T>> to share ownership across threads with safe mutable access. For message-passing workflows, use mpsc channels, preferably bounded sync_channel to apply backpressure.

When is unsafe code acceptable in Rust?▼

Unsafe is acceptable at FFI boundaries with documented safety invariants and in proven performance-critical paths like get_unchecked with a verified index bound. It is not acceptable for bypassing the borrow checker, convenience, or without a Safety comment.

Why should I avoid wildcard match arms in Rust enums?▼

Wildcard arms silently ignore new enum variants added later, hiding unhandled cases. Exhaustive matching forces the compiler to flag every new variant, making state handling explicit and preventing bugs during refactors.