AgentSkillsCN

rust-idioms

来自 Rust 社区的 Rust 重构与惯用模式指南(旧称“rust-refactor”)。在编写、审查或重构 Rust 代码时,应使用此技能,以确保代码符合惯用模式,并保持清晰的架构。适用于涉及 Rust 类型、所有权、错误处理、特质、模块、转换,或迭代器模式的任务。

SKILL.md
--- frontmatter
name: rust-idioms
description: Rust refactoring and idiomatic patterns guidelines from the Rust Community (formerly rust-refactor). This skill should be used when writing, reviewing, or refactoring Rust code to ensure idiomatic patterns and clean architecture. Triggers on tasks involving Rust types, ownership, error handling, traits, modules, conversions, or iterator patterns.

Rust Community Rust Refactoring Best Practices

Comprehensive refactoring and idiomatic patterns guide for Rust applications, maintained by the Rust Community. Contains 44 rules across 8 categories, prioritized by impact to guide automated refactoring and code generation.

When to Apply

Reference these guidelines when:

  • Writing new Rust code with strong type guarantees
  • Refactoring ownership and borrowing patterns
  • Designing error handling strategies
  • Creating public APIs with traits and generics
  • Organizing modules and controlling visibility

Rule Categories by Priority

PriorityCategoryImpactPrefix
1Type Safety & Newtype PatternsCRITICALtype-
2Ownership & BorrowingCRITICALown-
3Error Handling PatternsHIGHerr-
4API Design & TraitsHIGHapi-
5Module & VisibilityMEDIUM-HIGHmod-
6Conversion TraitsMEDIUMconv-
7Idiomatic PatternsMEDIUMidiom-
8Iterator & CollectionsLOW-MEDIUMiter-

Quick Reference

1. Type Safety & Newtype Patterns (CRITICAL)

2. Ownership & Borrowing (CRITICAL)

3. Error Handling Patterns (HIGH)

4. API Design & Traits (HIGH)

5. Module & Visibility (MEDIUM-HIGH)

6. Conversion Traits (MEDIUM)

7. Idiomatic Patterns (MEDIUM)

8. Iterator & Collections (LOW-MEDIUM)

How to Use

Read individual reference files for detailed explanations and code examples:

Full Compiled Document

For a single-file comprehensive guide, see AGENTS.md.