What problem does it solve?
Rust projects often drift away from idiomatic patterns and robust practices beyond what cargo clippy and rustfmt enforce. This skill codifies advanced Rust conventions to improve readability, safety, and maintainability.
Core Features & Use Cases
- Idioms: Prefer &str over &String in function parameters; use impl Trait in argument position for simple generics; prefer into()/from() over explicit constructors when a From impl exists; avoid overusing Rc/RefCell; use Cow<'_, str> to avoid allocations when possible; favor iterators and combinators over manual loops for readability.
- Error Handling: Use Result<T, E> for recoverable errors; propagate errors with ?, and apply context; leverage thiserror for library errors and anyhow for application errors.
- Ownership & Lifetimes: Structure data with ownership in mind; prefer owned types; minimize lifetimes; avoid long-lived references; use indices/keys for graph-like data.
- Testing: Tests in #[cfg(test)] mod tests; integration tests in tests/; use #[should_panic] where appropriate; aim for expressive assertions.
- Structure: One type per file when large; lib.rs as public API; module naming and privacy considerations.
- Concurrency: Use message passing; prefer tokio async runtimes; avoid crossing await points with MutexGuard; use Arc when sharing across threads.
Quick Start
Ask the assistant to apply Rust conventions to a given Cargo project.