
M05 Type Driven
Pushes you to encode invariants in the type system before reaching for runtime validation. When you're about to add an is_valid flag or validate in every function, this asks whether the compiler could catch it instead. Covers newtypes for primitive obsession, type state patterns for state machines, PhantomData for variance markers, and builder patterns for gradual construction. The "Error to Design Question" table is the real gem here, reframing common runtime checks as type design opportunities. Honestly most useful when you catch yourself writing the same validation logic in multiple places. Traces up to domain modeling when unclear what types to create, traces down to concrete patterns like sealed traits and zero-sized types.
- skills.sh installs
- 3.6K
- GitHub stars
- 1.6K
- last updated
- Aug 21, 2026
Install
$ npx -y skills add actionbook/rust-skills --skill m05-type-driven --agent claude-codeInstalls into .claude/skills of the current project.
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
Sponsors
Details
- Repository
- github.com/actionbook/rust-skills
- Categories
- Rust, Design & UI/UX
- First seen
- May 16, 2026
More from actionbook/rust-skills
All 38- M02 Resource3.6K
- M03 Mutability3.6K
- Rust Refactor Helper3.6K
- M12 Lifecycle3.5K
- M09 Domain3.5K
- M14 Mental Model3.5K
- M11 Ecosystem3.5K
- M13 Domain Error3.5K
- Unsafe Checker3.5K
- Rust Code Navigator3.4K
- Rust Trait Explorer3.4K
- Rust Call Graph3.4K
- Rust Symbol Analyzer3.4K
- Domain Web3.4K
- Domain Cli3.4K
- Rust Learner3.3K
- Rust Skill Creator3.3K
- Rust Deps Visualizer3.2K
- Meta Cognition Parallel3.2K
- Rust Daily3.2K
- Domain Embedded3.1K
- Domain Cloud Native3K
- Domain Fintech3K
- Domain Ml3K