rust-design-patterns

Guide Rust design pattern selection with decision criteria and examples.

Updated Jan 8, 2026
One-click install
npx skills add https://github.com/OlegHQ/agent-configs --skill rust-design-patterns-oleghq
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-design-patterns
Source: https://github.com/OlegHQ/agent-configs/tree/main/plugins/rust-dev/skills/rust-design-patterns
Command: npx skills add https://github.com/OlegHQ/agent-configs --skill rust-design-patterns-oleghq

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Helps Rust developers write maintainable, scalable code by applying design patterns and idiomatic abstractions rather than ad hoc solutions.

Core Features & Use Cases

  • Guidance on when to prefer Enum+Match vs Trait+Impl based on openness and extensibility.
  • Techniques for safe state transitions (Typestate, RAII, and compile-time checks) and choosing appropriate abstractions.
  • Practical patterns coverage including Strategy, Template Method, Decorator, Adapter, Bridge, and more with Rust idioms.

Quick Start

Describe a Rust task and request an implementation outline using the most appropriate Rust pattern.

Frequently Asked Questions about rust-design-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
When should I use Enum+Match vs Trait-based abstractions in Rust?

Choose Enum+Match in Rust when the set of variants is closed and known upfront, and prefer Trait+Impl abstractions when you need extensibility and open-ended polymorphism. Decision criteria are based on openness and future extensibility requirements.

How do I implement safe state transitions in Rust at compile time?

Implement safe state transitions in Rust using the Typestate pattern and RAII to enforce valid state changes via compile-time checks. This technique encodes state machines directly into the type system to eliminate runtime errors.

What is the best way to apply the Strategy and Decorator design patterns in Rust?

Apply the Strategy and Decorator patterns in Rust by utilizing traits to define shared behavior and composition to wrap objects. This provides idiomatic, flexible abstractions rather than relying on ad hoc solutions for feature development.

Can I use Rust idioms to refactor ad hoc abstractions into maintainable code?

Yes, you can refactor ad hoc abstractions into maintainable Rust code by applying idiomatic design patterns like Adapter, Bridge, and Template Method. This ensures scalable architecture decisions and consistent design guidance during refactoring.

What are the limitations of using Typestate patterns for Rust architecture?

The Typestate pattern in Rust can increase code complexity and cause signature bloat when state machines are highly dynamic. It is best constrained to scenarios where compile-time checks are absolutely critical for preventing invalid operations.