← スキル一覧に戻る

rust-idioms
by pproenca
A collection of AI agent skills following the Agent Skills open format
⭐ 1🍴 0📅 2026年1月25日
SKILL.md
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
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Type Safety & Newtype Patterns | CRITICAL | type- |
| 2 | Ownership & Borrowing | CRITICAL | own- |
| 3 | Error Handling Patterns | HIGH | err- |
| 4 | API Design & Traits | HIGH | api- |
| 5 | Module & Visibility | MEDIUM-HIGH | mod- |
| 6 | Conversion Traits | MEDIUM | conv- |
| 7 | Idiomatic Patterns | MEDIUM | idiom- |
| 8 | Iterator & Collections | LOW-MEDIUM | iter- |
Quick Reference
1. Type Safety & Newtype Patterns (CRITICAL)
type-newtype-units- Use newtype pattern for unit safetytype-newtype-invariants- Encode invariants in newtype constructorstype-non-exhaustive-enums- Use non-exhaustive for extensible enumstype-phantom-data- Use PhantomData for type-level statetype-strong-typing-strings- Replace stringly-typed APIs with strong typestype-builder-required-fields- Use typestate builders for required fields
2. Ownership & Borrowing (CRITICAL)
own-prefer-borrowing- Prefer borrowing over ownership in parametersown-cow-conditional-clone- Use Cow for conditional ownershipown-accept-borrowed-types- Accept borrowed types over owned referencesown-return-owned-for-flexibility- Return owned types for caller flexibilityown-avoid-unnecessary-clone- Avoid unnecessary clone callsown-lifetime-elision- Leverage lifetime elision rules
3. Error Handling Patterns (HIGH)
err-use-result-not-panic- Use Result instead of panic! for recoverable errorserr-thiserror-for-libraries- Use thiserror for library error typeserr-anyhow-for-applications- Use anyhow for application error handlingerr-question-mark-propagation- Use the question mark operator for error propagationerr-option-for-absence- Use Option for absence, not sentinel values
4. API Design & Traits (HIGH)
api-derive-common-traits- Derive common traits for public typesapi-impl-standard-traits- Implement standard traits for ergonomic APIsapi-generic-bounds- Use trait bounds for generic flexibilityapi-sealed-traits- Use sealed traits to prevent external implementationapi-builder-pattern- Use builder pattern for complex constructionapi-extension-traits- Use extension traits to add methods to foreign types
5. Module & Visibility (MEDIUM-HIGH)
mod-minimize-pub-api- Minimize public API surfacemod-pub-use-reexports- Use pub use for clean module re-exportsmod-split-large-modules- Split large modules into submodulesmod-crate-prefix-imports- Use crate:: prefix for internal importsmod-tests-submodule- Use tests submodule for unit tests
6. Conversion Traits (MEDIUM)
conv-impl-from-not-into- Implement From instead of Intoconv-asref-for-flexibility- Accept AsRef for flexible string parametersconv-impl-deref-for-newtypes- Implement Deref for transparent newtype accessconv-tryfrom-for-fallible- Use TryFrom for fallible conversionsconv-inner-function-pattern- Use inner function pattern to reduce monomorphization
7. Idiomatic Patterns (MEDIUM)
idiom-default-trait- Implement Default instead of new() without argumentsidiom-constructor-naming- Follow constructor naming conventionsidiom-let-else- Use let-else for early returns on pattern match failureidiom-struct-update-syntax- Use struct update syntax for partial overridesidiom-destructuring-assignment- Use destructuring for multiple returns and field accessidiom-match-guards- Use match guards for complex conditions
8. Iterator & Collections (LOW-MEDIUM)
iter-prefer-iterators-over-loops- Prefer iterator methods over manual loopsiter-use-collect-turbofish- Use turbofish for explicit collect typeiter-filter-map-combined- Use filter_map for combined filter and transformiter-avoid-collect-then-iterate- Avoid collecting then iteratingiter-enumerate-for-indices- Use enumerate instead of manual index tracking
How to Use
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
Full Compiled Document
For a single-file comprehensive guide, see AGENTS.md.
スコア
総合スコア
60/100
リポジトリの品質指標に基づく評価
✓SKILL.md
SKILL.mdファイルが含まれている
+20
✓LICENSE
ライセンスが設定されている
+10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
○タグ
1つ以上のタグが設定されている
0/5
レビュー
💬
レビュー機能は近日公開予定です