← ClaudeAtlas

rustlisted

This skill should be used when the user works with Rust files (.rs), asks about "ownership", "borrowing", "lifetimes", "Result/Option", "traits", or discusses memory safety and type-driven design. Provides patterns for ownership, error handling, type system usage, and safe concurrency.
dean0x/devflow · ★ 19 · Code & Development · score 80
Install: claude install-skill dean0x/devflow
# Rust Patterns Reference for Rust-specific patterns, ownership model, and type-driven design. ## Iron Law > **MAKE ILLEGAL STATES UNREPRESENTABLE** [15][2, C-VALIDATE] > > Encode invariants in the type system. If a function can fail, return `Result`. If a value > might be absent, return `Option`. If a state transition is invalid, make it uncompilable. > Runtime checks are a fallback, not a strategy. ## When This Skill Activates - Working with Rust codebases - Designing type-safe APIs - Managing ownership and borrowing - Implementing error handling - Writing concurrent code --- ## Ownership & Borrowing [1, Ch.4][11] Prefer borrowing over cloning — accept `&str` not `String`, `&[T]` not `&Vec<T>` [2, C-BORROW]. The borrow checker enforces the Stacked Borrows aliasing model at compile time [6][11]. Lifetime annotations required when elision rules can't resolve ambiguity [1, Ch.10]. ```rust // BAD: fn process(data: String) — takes ownership unnecessarily fn process(data: &str) -> usize { data.len() } // GOOD: borrow [2, C-BORROW] ``` See `references/ownership.md` for elision rules, interior mutability, Cow, and Pin. --- ## Error Handling [8][9][16] Use `thiserror` for libraries (typed, matchable variants); `anyhow` for applications (ergonomic propagation). Never use `Box<dyn Error>` in library APIs [8][16]. ```rust #[derive(thiserror::Error, Debug)] pub enum AppError { #[error("IO error reading {path}")] Io { path: String, #[source] source: io::Error },