Development
rust-patterns - Claude MCP Skill
Idiomatic Rust patterns for ownership, errors, traits, and configuration. Use when: - Writing or reviewing Rust code - Designing error handling with Result and thiserror - Implementing traits and composition patterns - Working with ownership and borrowing - Configuring Cargo features Keywords: Rust, ownership, borrowing, Result, thiserror, anyhow, trait, lifetimes, Cargo features, unsafe
SEO Guide: Enhance your AI agent with the rust-patterns tool. This Model Context Protocol (MCP) server allows Claude Desktop and other LLMs to idiomatic rust patterns for ownership, errors, traits, and configuration. use when: - writing or rev... Download and configure this skill to unlock new capabilities for your AI workflow.
Documentation
SKILL.md# Rust Patterns
Ownership-first, zero-cost abstractions, no hidden complexity.
## Error Handling
**Always use `Result<T, E>`. Never panic for expected failures:**
```rust
// Use thiserror for library error types
#[derive(Debug, thiserror::Error)]
pub enum UserError {
#[error("user not found: {0}")]
NotFound(String),
#[error("invalid email format")]
InvalidEmail,
#[error("database error: {0}")]
Database(#[from] sqlx::Error),
}
// Use anyhow for applications (context chaining)
fn fetch_user(id: &str) -> anyhow::Result<User> {
let user = db.get(id)
.context("fetching user from database")?;
Ok(user)
}
```
**Propagate with `?`, add context at boundaries.**
## Ownership Patterns
**Borrowing > Cloning:**
```rust
// Good: Borrow for read-only
fn process(items: &[Item]) -> usize { ... }
// Good: Take ownership when storing/transforming
fn consume(items: Vec<Item>) -> Output { ... }
// Avoid: Excessive cloning
fn bad(items: &Vec<Item>) {
let copy = items.clone(); // Usually unnecessary
}
```
**Fight the borrow checker → redesign, don't circumvent.**
## Trait Design
**Small, focused traits (1-3 methods):**
```rust
trait Readable {
type Item;
fn read(&self) -> Self::Item;
}
trait Writable {
type Item;
fn write(&mut self, item: Self::Item);
}
// Compose through bounds
fn copy<R, W>(src: &R, dst: &mut W)
where
R: Readable<Item = Vec<u8>>,
W: Writable<Item = Vec<u8>>,
{ ... }
```
**Consumer-side interfaces. Static dispatch by default.**
## Configuration
**Cargo features for compile-time options:**
```toml
[features]
default = ["json"]
json = ["serde_json"]
database = ["sqlx"]
full = ["json", "database"]
```
```rust
#[cfg(feature = "json")]
pub mod json_support { ... }
```
## Unsafe
**Minimize. Document with `// SAFETY:` comments:**
```rust
// SAFETY: We verified ptr is non-null and properly aligned
// in the caller's bounds check above
unsafe { *ptr }
```
Abstract behind safe interfaces.
## Anti-Patterns
- `unwrap()` / `expect()` for recoverable errors
- `Result<T, String>` (use typed errors)
- Excessive `Rc<RefCell<T>>` (redesign ownership)
- Monolithic traits (10+ methods)
- Reflection instead of generics
- Fighting borrow checker with unsafeSignals
Information
- Repository
- phrazzld/claude-config
- Author
- phrazzld
- Last Sync
- 3/2/2026
- Repo Updated
- 3/1/2026
- Created
- 1/18/2026
Reviews (0)
No reviews yet. Be the first to review this skill!
Related Skills
cursorrules
CrewAI Development Rules
cn-check
Install and run the Continue CLI (`cn`) to execute AI agent checks on local code changes. Use when asked to "run checks", "lint with AI", "review my changes with cn", or set up Continue CI locally.
CLAUDE
CLAUDE.md
knowledge-base
Knowledge Base - Domain & Product-Specific Information
Related Guides
Mastering the Oracle CLI: A Complete Guide to the Claude Skill for Database Professionals
Learn how to use the oracle Claude skill. Complete guide with installation instructions and examples.
Python Django Best Practices: A Comprehensive Guide to the Claude Skill
Learn how to use the python django best practices Claude skill. Complete guide with installation instructions and examples.
Optimize Rell Blockchain Code: A Comprehensive Guide to the Claude Skill
Learn how to use the optimize rell blockchain code Claude skill. Complete guide with installation instructions and examples.