
M05 Type Driven
The m05-type-driven skill teaches developers how to use Rust's type system to prevent invalid states and encode invariants at compile time rather than relying on runtime validation. It covers patterns like newtypes, type state, PhantomData, marker traits, and builders that allow developers to make invalid states unrepresentable. This skill is for Rust engineers building robust systems who need to shift validation logic from runtime checks to compile-time type constraints.
- skills.sh installs
- 786
- GitHub stars
- 1.3K
- last updated
- Jul 14, 2026
Install
$ npx -y skills add zhanghandong/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
Promote your product hereReach 125k+ visitors monthlyPromote your product hereReach 125k+ visitors monthly
Agent CaffeineSponsoredClose your lid, come back to finished work
SnugSponsoredThe clipboard manager for the AI eraPromote your product hereReach 125k+ visitors monthly
WaxSponsoredBlock anything with supervision, without erasing your iPhonePromote your product hereReach 125k+ visitors monthly
knobsSponsoredSee your site on any phone, any day, in any language
Details
- Repository
- github.com/zhanghandong/rust-skills
- Category
- Rust
More from zhanghandong/rust-skills
All 34- M02 Resource783
- M03 Mutability773
- M12 Lifecycle764
- M14 Mental Model751
- M09 Domain750
- M11 Ecosystem747
- M13 Domain Error738
- Rust Trait Explorer731
- Rust Code Navigator728
- Unsafe Checker726
- Domain Cli709
- Rust Symbol Analyzer702
- Rust Call Graph699
- Rust Router698
- Rust Learner688
- Rust Deps Visualizer684
- Rust Skill Creator670
- Domain Web648
- Meta Cognition Parallel635
- Rust Daily635
- Domain Embedded625
- Domain Cloud Native596
- Domain Fintech581
- Domain Ml573
Recommended
More Rust6
rhwp-advancednomadamas/k-skillDebug HWP layout, dump document IR, compare versions, extract thumbnails, and unlock read-only HWPs with the upstream rhwp Rust CLI (export-svg/dump/dump-pages/10.3Kskills.sh installs