rust-patterns

Applies idiomatic Rust patterns for ownership, error handling, traits, and concurrency.

1|Updated Oct 11, 2025
One-click install
npx skills add https://github.com/ibytechaos/claude --skill rust-patterns-ibytechaos
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-patterns
Source: https://github.com/ibytechaos/claude/tree/main/plugins/everything-claude-code/skills/rust-patterns
Command: npx skills add https://github.com/ibytechaos/claude --skill rust-patterns-ibytechaos

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Rust developers often write code that compiles but violates idiomatic conventions—overusing unwrap(), cloning to silence the borrow checker, or modeling states loosely—leading to panics, hidden bugs, and unmaintainable codebases. ## Core Features & Use Cases - Ownership and Borrowing Guidance: Enforces borrowing over cloning, Cow for flexible ownership, and newtype patterns for type-safe APIs. - Structured Error Handling: Promotes Result/? propagation with thiserror for libraries and anyhow for applications, banning unwrap() in production. - Concurrency and Async Patterns: Covers Arc<Mutex<T>>, channels with backpressure, and Tokio-based async with timeouts and task spawning. - Use Case: When reviewing a Rust pull request that panics on I/O errors and uses wildcard match arms, apply this Skill to refactor toward typed errors, exhaustive matching, and minimal pub surfaces. ## Quick Start Review my Rust code and refactor it to follow idiomatic patterns for error handling, ownership, and concurrency.

Frequently Asked Questions about rust-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I handle errors idiomatically in Rust?

Propagate errors with Result and the ? operator instead of unwrap(). Use thiserror to define typed error enums in libraries and anyhow with context for application-level error handling.

When should I use thiserror vs anyhow in Rust?

Use thiserror for library code where callers need structured, matchable error types. Use anyhow for application code where flexible error propagation with context messages matters more than typed variants.

How do I share mutable state across threads in Rust?

Wrap the state in Arc<Mutex<T>> to share ownership across threads with synchronized access. For message-passing workflows, use mpsc channels, preferably bounded sync_channel for backpressure.

Why should I avoid unwrap() in Rust production code?

unwrap() panics on None or Err, crashing the program at runtime. Propagating with ? lets callers decide how to handle failures and preserves error context through the call stack.

When is unsafe code acceptable in Rust?

Unsafe is acceptable at FFI boundaries with documented invariants or in proven performance-critical paths, always with a Safety comment. It is not acceptable for bypassing the borrow checker or convenience.

How should I organize a Rust crate's module structure?

Organize modules by domain (auth, orders, db) rather than by type. Keep visibility minimal with pub(crate) for internal APIs and re-export only the intended public surface from lib.rs.