
M05 Type Driven
Rust type-driven design patterns that make invalid states unrepresentable at compile time.
- skills.sh installs
- 3.7K
- GitHub stars
- 1.6K
- last updated
- Aug 21, 2026
Own this skill? Claim it
What it does
- Covers newtypes, type state, PhantomData, marker traits, builders, sealed traits, and zero-sized types
- Includes a thinking prompt, error-to-design-question table, and decision guide for choosing a pattern
- Enforces validation at construction or state transition so invariants are checked once rather than at runtime
- Designed for Rust developers replacing boolean flags and stringly typed values with compiler-checked types
Install
$ npx -y skills add actionbook/rust-skills --skill m05-type-driven -yInstalls into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.
Files
Type-Driven Design
Layer 1: Language Mechanics
Core Question
How can the type system prevent invalid states?
Before reaching for runtime checks:
- Can the compiler catch this error?
- Can invalid states be unrepresentable?
- Can the type encode the invariant?
Error → Design Question
| Pattern | Don't Just Say | Ask Instead |
|---|---|---|
| Primitive obsession | "It's just a string" | What does this value represent? |
| Boolean flags | "Add an is_valid flag" | Can states be types? |
| Optional everywhere | "Check for None" | Is absence really possible? |
| Validation at runtime | "Return Err if invalid" | Can we validate at construction? |
Thinking Prompt
Before adding runtime validation:
-
Can the type encode the constraint?
- Numeric range → bounded types or newtypes
- Valid states → type state pattern
- Semantic meaning → newtype
-
When is validation possible?
- At construction → validated newtype
- At state transition → type state
- Only at runtime → Result with clear error
Details
- Repository
- github.com/actionbook/rust-skills
- Category
- Rust
- First seen
- May 16, 2026
More from actionbook/rust-skills
All 38- M04 Zero Cost3.7K
- M02 Resource3.7K
- Rust Refactor Helper3.7K
- M03 Mutability3.7K
- M12 Lifecycle3.6K
- M09 Domain3.6K
- M14 Mental Model3.6K
- M13 Domain Error3.6K
- M11 Ecosystem3.6K
- Unsafe Checker3.6K
- Rust Code Navigator3.6K
- Rust Trait Explorer3.5K
- Rust Call Graph3.5K
- Rust Symbol Analyzer3.5K
- Domain Web3.5K
- Domain Cli3.5K
- Rust Learner3.4K
- Rust Skill Creator3.4K
- Rust Deps Visualizer3.3K
- Meta Cognition Parallel3.3K
- Rust Daily3.3K
- Domain Embedded3.2K
- Domain Cloud Native3.2K
- Domain Fintech3.1K
Similar to M05 Type Driven
More Rust
m09-domainactionbook/rust-skills3.6K installsDomain modeling guide mapping DDD concepts to Rust patterns, ownership, and invariant enforcement.
m04-zero-costactionbook/rust-skills3.7K installsChoose generics or trait objects by asking when the type is known, with error-driven design checks.
rust-implementpproenca/dot-skills254 installsMulti-pass Rust workflow that designs types first, implements, simplifies, then runs an automated lint against the code.
rust-engineerjeffallan/claude-skills6.8K installsIdiomatic Rust engineering skill covering ownership, lifetimes, traits, async tokio, and error handling.