What problem does it solve?
This skill helps you avoid common Rust pitfalls by enforcing idiomatic patterns for ownership, error handling, modeling state with enums, and safe concurrency so your code becomes safer, clearer, and more maintainable.
Core Features & Use Cases
- Ownership and borrowing guidance: Prefer borrowing over cloning, and use
Cow to flexibly avoid unnecessary allocations.
- Production-grade error handling: Use
Result with ?, avoid unwrap(), and distinguish typed library errors with thiserror from flexible application errors with anyhow.
- Correct modeling and control flow: Use enums and exhaustive pattern matching to make illegal states unrepresentable, avoiding wildcard matches for business-critical logic.
- Type-safe abstractions: Apply generics, trait objects appropriately, and use the newtype pattern to prevent mixing primitive IDs.
- Concurrency best practices: Use
Arc<Mutex<T>> for shared mutable state and channels or async/Tokio patterns for message passing and timeouts.
- Project structure and API visibility: Organize modules by domain and keep a minimal public surface with
pub(crate) where appropriate.
Real-world example
When building a backend service that processes concurrent requests, this skill guides how to structure modules, propagate errors cleanly, model request state transitions with enums, and implement concurrency safely without data races.
Quick Start
Use the rust-patterns skill to review or refactor your Rust codebase for idiomatic ownership, safe error handling, exhaustive enum matching, and production-ready concurrency patterns.