rust-refactor

📁 pproenca/dot-skills 📅 Feb 14, 2026
28
总安装量
28
周安装量
#13329
全站排名
安装命令
npx skills add https://github.com/pproenca/dot-skills --skill rust-refactor

Agent 安装分布

codex 25
gemini-cli 24
github-copilot 24
opencode 22
kimi-cli 22
amp 21

Skill 文档

Rust Refactor Best Practices

Architectural refactoring guide for Rust applications. Contains 91 rules across 10 categories, prioritized by impact from critical (type safety, ownership) to incremental (iterator idioms).

When to Apply

  • Refactoring existing Rust codebases or planning large-scale restructuring
  • Reviewing PRs for architectural issues and code smells
  • Designing type-safe APIs with proper error handling
  • Organizing Rust project structure with Cargo workspaces
  • Improving module boundaries and visibility control
  • Applying consistent naming conventions (RFC 430)
  • Replacing stringly-typed APIs with strong types

Rule Categories

Category Impact Rules Key Topics
Type Safety & Patterns CRITICAL 20 Newtypes, typestate builders, PhantomData, enums, trait objects, associated types
Ownership & Borrowing CRITICAL 6 Borrowing, Cow, lifetime elision, clone avoidance
Error Handling HIGH 15 thiserror/anyhow, two-tier strategy, context, graceful degradation
API Design & Traits HIGH 6 Sealed traits, extension traits, generic bounds, builder pattern
Project Organization HIGH 6 Cargo workspaces, crate separation, feature grouping
Module & Visibility MEDIUM-HIGH 9 Re-exports, visibility control, test co-location, module splitting
Naming Conventions MEDIUM-HIGH 13 RFC 430, snake_case, PascalCase, predicates, unit suffixes
Conversion Traits MEDIUM 5 From/Into, AsRef, TryFrom, Deref
Idiomatic Patterns MEDIUM 6 Default, let-else, destructuring, match guards
Iterator & Collections LOW-MEDIUM 5 Iterator methods, collect turbofish, filter_map

Quick Reference

Critical patterns — get these right first:

  • Use newtype patterns to prevent unit confusion and encode invariants
  • Prefer borrowing over ownership in function parameters
  • Use thiserror for library errors, anyhow for application errors
  • Use typestate builders for compile-time required field enforcement

Common mistakes — avoid these anti-patterns:

  • Stringly-typed APIs instead of strong types
  • Unnecessary clone calls when borrowing would work
  • panic! for recoverable errors instead of Result
  • Over-exposing internal types with pub visibility

Table of Contents

  1. Type Safety & Patterns — CRITICAL
  2. Ownership & Borrowing — CRITICAL
  3. Error Handling — HIGH
  4. API Design & Traits — HIGH
  5. Project Organization — HIGH
  6. Module & Visibility — MEDIUM-HIGH
  7. Naming Conventions — MEDIUM-HIGH
  8. Conversion Traits — MEDIUM
  9. Idiomatic Patterns — MEDIUM
  10. Iterator & Collections — LOW-MEDIUM

References

  1. https://rust-lang.github.io/api-guidelines/
  2. https://rust-unofficial.github.io/patterns/
  3. https://doc.rust-lang.org/book/
  4. https://www.lurklurk.org/effective-rust/
  5. https://rust-lang.github.io/rust-clippy/

Related Skills

  • For performance optimization, see rust-optimise skill