rust-patterns

Apply idiomatic Rust best practices for ownership, error handling, and concurrency.

Updated May 9, 2026
One-click install
npx skills add https://github.com/kk20300113-png/my-claude-skills --skill rust-patterns-kk20300113-png
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-patterns
Source: https://github.com/kk20300113-png/my-claude-skills/tree/main/rust-patterns
Command: npx skills add https://github.com/kk20300113-png/my-claude-skills --skill rust-patterns-kk20300113-png

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill eliminates the guesswork of writing idiomatic, safe, and performant Rust code, helping developers avoid common borrow checker errors, runtime panics from unwrap() misuse, and non-performant implementations that lead to bugs and maintenance overhead.

Core Features & Use Cases

  • Idiomatic Rust Best Practices: Covers ownership and borrowing, error handling with Result/thiserror/anyhow, enum pattern matching, traits and generics, safe concurrency, and module structure aligned with Rust community standards.
  • Bug and Anti-Pattern Prevention: Explicitly calls out common pitfalls like unnecessary cloning, unsafe code misuse, and blocking in async contexts to prevent runtime failures.
  • Use Case: Use this Skill when building new Rust applications or libraries, refactoring legacy Rust codebases, or reviewing pull requests to ensure code follows safe, performant conventions.

Quick Start

Use the rust-patterns skill to review the attached Rust microservice code and suggest improvements for ownership handling and error propagation.

Frequently Asked Questions about rust-patterns

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

FAQPage Schema
What are idiomatic Rust patterns for safe memory management and ownership?

Idiomatic Rust patterns for safe memory management use strict ownership and borrowing rules to enforce memory safety at compile time. These patterns prevent common borrow checker errors, eliminate unnecessary cloning, and ensure performant resource handling without unsafe code.

How do I handle errors in Rust without causing runtime panics from unwrap?

Handle errors in Rust by using the Result type for explicit error propagation instead of unwrap. Applying idiomatic error handling patterns with thiserror or anyhow ensures robust failure management and prevents runtime panics from unwrap misuse.

What's the best way to refactor a Rust codebase to follow safe concurrency patterns?

The best way to refactor a Rust codebase for safe concurrency is to apply standardized community patterns that prevent blocking in async contexts. Adopting safe concurrency patterns eliminates data races through strict borrowing rules while maintaining high performance.

Can I use these Rust best practices for reviewing pull requests and designing module structures?

Yes, you can use these Rust best practices for reviewing pull requests and designing crate module structures. The guidelines standardize public API surface design, enforce enum pattern matching, and verify trait usage to ensure codebase maintainability.

Why does my Rust code fail the borrow checker and how can I fix it?

Rust code fails the borrow checker when violating ownership rules, such as having mutable and immutable references overlap. Fixing borrow checker errors involves applying idiomatic borrowing patterns and removing unnecessary cloning to satisfy compiler constraints safely.