agentsclimarketplace

Rust refactor

Skill ComeOnOliver/skillshub/skills/pproenca/dot-skills/rust-refactor

🧠 The right skill, one API call. AI agent skills registry with token-efficient skill resolution. 5,000+ skills from 500+ top repos.

Install
npx -y skills add ComeOnOliver/skillshub --skill rust-refactor

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

SKILL.md

12.7 KB, as published. Nobody here has run it

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

CategoryImpactRulesKey Topics
Type Safety & PatternsCRITICAL20Newtypes, typestate builders, PhantomData, enums, trait objects, associated types
Ownership & BorrowingCRITICAL6Borrowing, Cow, lifetime elision, clone avoidance
Error HandlingHIGH15thiserror/anyhow, two-tier strategy, context, graceful degradation
API Design & TraitsHIGH6Sealed traits, extension traits, generic bounds, builder pattern
Project OrganizationHIGH6Cargo workspaces, crate separation, feature grouping
Module & VisibilityMEDIUM-HIGH9Re-exports, visibility control, test co-location, module splitting
Naming ConventionsMEDIUM-HIGH13RFC 430, snake_case, PascalCase, predicates, unit suffixes
Conversion TraitsMEDIUM5From/Into, AsRef, TryFrom, Deref
Idiomatic PatternsMEDIUM6Default, let-else, destructuring, match guards
Iterator & CollectionsLOW-MEDIUM5Iterator 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

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.