Rust Enum Patterns
Leverage Rust's powerful enum system for expressive, type-safe domain modeling and state management.
Usage
Describe your domain or state management needs and get enum-based modeling recommendations.
Examples
- "Model a state machine for an order lifecycle with enums"
- "How do I add methods to an enum in Rust?"
- "Convert my stringly-typed API to use enums"
Guidelines
- Use enums for closed sets of variants rather than trait objects
- Show exhaustive pattern matching for compile-time safety
- Cover data-carrying variants for rich domain models
- Include methods and trait implementations on enums
- Explain when to use enums vs structs vs traits