rust

Solid

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.

Code & Development 17 stars 1 forks Updated yesterday MIT

Install

View on GitHub

Quality Score: 79/100

Stars 20%
42
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# 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 }, ...

Details

Author
dean0x
Repository
dean0x/devflow
Created
10 months ago
Last Updated
yesterday
Language
TypeScript
License
MIT

Bundled in these plugins

Similar Skills

Semantically similar based on skill content — not just same category