rust-design-patterns
Skill11 starsChanged 9 days agoMITView on GitHub
Rust design pattern and idiom guidance. Use when choosing, implementing, or reviewing Rust patterns such as newtypes, builders, RAII guards, traits, strategy, visitor, command, compose-structs, small crates, contained unsafe modules, custom traits for complex bounds, macros, or ownership-driven API design. Use rust-antipatterns for smell-focused audits and load rust-engineering whenever applying or implementing a pattern.
3 other projects use a version of this.
Adopted by
Most recently taken up by
- adxptived/Rust-Skillstheir own version, first seen Oct 17, 2026
- ahonn/dotfilestheir own version, first seen Sep 10, 2026
- botirkhaltaev/botir-skillstheir own version, first seen Jul 24, 2026
Other versions3 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 3
- ahonn/dotfiles★ 62same name
- botirkhaltaev/botir-skills★ 4same name
- adxptived/Rust-Skills★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository70 other files it gives its agents.
- AGENTS.mdAGENTS.md
- adversarial-reviewSkill
- api-designSkill
- architecture-reviewSkill
- behavior-driven-developmentSkill
- brainstormingSkill
- ci-release-engineeringSkill
- clean-architectureSkill
- code-reviewSkill
- container-engineeringSkill
- create-agent-skillSkill
- csharp-dotnet-engineeringSkill
- css-scss-stylingSkill
- data-platform-engineeringSkill
- dependency-supply-chain-reviewSkill
- digital-asset-managementSkill
- documentation-engineeringSkill
- domain-driven-designSkill
- domain-modelingSkill
- donsetch-web-researchSkill
- gherkinSkill
- git-commitSkill
- git-workflowsSkill
- hexagonal-architectureSkill
- impeccableSkill
- internationalization-localizationSkill
- javascript-typescript-engineeringSkill
- justfilesSkill
- mcp-server-engineeringSkill
- mysql-mariadb-sql-engineeringSkill
- observability-engineeringSkill
- onion-architectureSkill
- parallelism-engineeringSkill
- performance-reviewSkill
- playwright-e2eSkill
- postgresql-sql-engineeringSkill
- prompt-engineering-reviewSkill
- python-antipatternsSkill
- python-design-patternsSkill
- python-engineeringSkill
- random-data-identifiersSkill
- release-readinessSkill
- review-verification-protocolSkill
- root-cause-analysisSkill
- ruby-engineeringSkill
- rust-antipatternsSkill
- rust-async-webSkill
- rust-code-reviewSkill
- rust-desktop-guiSkill
- rust-engineeringSkill
- rust-persistence-sqlSkill
- rust-testing-qualitySkill
- script-engineeringSkill
- security-review-evidenceSkill
- security-reviewSkill
- semantic-versioningSkill
- sql-engineeringSkill
- sqlite-sql-engineeringSkill
- suggest-lucide-iconsSkill
- svelte-sveltekit-engineeringSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
12 rules. 0 are common, 10 are distinctive, and 2 are very specific to this project.
0
Common
Most of the 3 edited versions we read keep these.
10
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 8
Use this skill to choose idiomatic Rust patterns that solve a real design problem.
- Very specific: line 22
Do not use this skill to justify decorative abstractions.
- Distinctive: line 33
Prefer simple language features before patterns: functions, enums, pattern matching, modules, visibility, iterators, and traits.
- Distinctive: line 35
Add abstraction only when it removes real duplication, makes invalid states harder to express, protects a boundary, or improves caller …
- Distinctive: line 37
Keep public APIs explicit about ownership, errors, feature flags, and caller obligations.
- Distinctive: line 39
Verify with tests, doctests, compile-fail examples, or review of generated macro expansion when the pattern creates caller-facing contracts.
- Distinctive: line 51
Builder: use when construction has many optional fields, validation, or staged defaults.
- Distinctive: line 53
Traits as ports or strategies: use traits for real substitution, dependency inversion, test fakes, plugin points, or generic algorithms.
- Distinctive: line 56
Compose structs: prefer composition and explicit fields over inheritance emulation or broad base traits.
- Very specific: line 64
Macros: use macro_rules! or procedural macros only when functions, traits, derives, builders, or generics cannot provide a clear caller …
- Distinctive: line 73
Clean / Hexagonal / Onion: use traits or functions for outbound ports only when adapters, infrastructure, or tests need a boundary.
- Distinctive: line 76
BDD: keep examples at public API, use-case, or adapter boundaries.
“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Rust Design Patterns
Use this skill to choose idiomatic Rust patterns that solve a real design problem. Rust patterns should exploit ownership, enums, traits, modules, and the type system rather than copying object-oriented patterns from other languages.
Use When
- A Rust API, crate boundary, module structure, domain type, trait, macro, or refactor needs an idiomatic pattern choice.
- The code has multiple real implementations, construction complexity, ownership/lifetime constraints, state transitions, or safety boundaries.
- A DDD, TDD, Clean, Hexagonal, or Onion design needs Rust-specific expression.
- Review comments or implementation plans mention pattern names or ask for a more idiomatic Rust design.
Do not use this skill to justify decorative abstractions. Use
rust-antipatterns when the task is mainly to
find or remove generated-code smells. Advice-only pattern selection may use this
skill independently; load rust-engineering
whenever applying or implementing the pattern.
Selection Rules
- Inspect existing crate/module conventions before naming a pattern.
- Name the design pressure: invariant, ownership, substitution, construction, lifetime, extensibility, safety, testing, or dependency direction.
- Prefer simple language features before patterns: functions, enums, pattern matching, modules, visibility, iterators, and traits.
- Add abstraction only when it removes real duplication, makes invalid states harder to express, protects a boundary, or improves caller ergonomics.
- Keep public APIs explicit about ownership, errors, feature flags, and caller obligations.
- Verify with tests, doctests, compile-fail examples, or review of generated macro expansion when the pattern creates caller-facing contracts.
Patterns To Prefer
- Newtype: wrap primitive or external types when a domain concept, unit, validation rule, secrecy boundary, or API distinction matters.
- Enums and type states: represent mutually exclusive states, protocol phases, command variants, and impossible combinations instead of parallel booleans or optional fields.
- RAII guards: tie cleanup, lock release, resource lifetime, or scoped state
restoration to ownership and
Drop. - Builder: use when construction has many optional fields, validation, or staged defaults. Prefer normal constructors for small required data.
- Traits as ports or strategies: use traits for real substitution, dependency inversion, test fakes, plugin points, or generic algorithms. Keep trait bounds close to the item that needs them.
- Compose structs: prefer composition and explicit fields over inheritance emulation or broad base traits.
- Small crates or modules: split only when release, dependency, compile-time, ownership, or architectural boundaries earn it.
- Contained unsafe modules: isolate unsafe code behind a small safe API with documented invariants and focused tests.
- Custom traits for complex bounds: hide repeated generic bounds when the alias expresses a real capability and improves diagnostics.
- Macros: use
macro_rules!or procedural macros only when functions, traits, derives, builders, or generics cannot provide a clear caller experience.
Architecture And Methods
- DDD: encode value objects, invariants, and state transitions with newtypes, enums, constructors, and domain methods. Keep persistence and framework types out of domain APIs.
- Clean / Hexagonal / Onion: use traits or functions for outbound ports only when adapters, infrastructure, or tests need a boundary. Use modules/crates and visibility to enforce inward dependencies.
- BDD: keep examples at public API, use-case, or adapter boundaries; avoid scenario wording that depends on private Rust types.
- TDD: drive small domain rules with synchronous unit tests, use-case workflows with fakes, adapters with integration tests, and macro misuse with doctests or compile-fail tests.
Review Checklist
- Does the pattern solve a named problem in this codebase?
- Does ownership match responsibility without avoidable clones or shared mutation?
- Are invalid states unrepresentable where the type system can reasonably do so?
- Are traits, generics, lifetimes, and feature flags as narrow as the contract allows?
- Are error types appropriate for library versus application edges?
- Are examples, tests, or compile-time checks present for public contracts?
Common Mistakes
- Importing class-heavy patterns when enums, traits, functions, or modules are simpler.
- Creating one trait per struct without real substitution or dependency inversion.
- Using builders for ordinary required construction.
- Turning every boundary into async because one adapter performs I/O.
- Adding macros before proving ordinary Rust cannot express the API clearly.
- Treating pattern catalog names as proof that a design belongs in production.
Source Anchors
- Rust Design Patterns, Design Patterns.
- Rust Design Patterns, Summary.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

