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-code

Installs 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

PatternDon't Just SayAsk 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:

  1. Can the type encode the constraint?

    • Numeric range → bounded types or newtypes
    • Valid states → type state pattern
    • Semantic meaning → newtype
  2. 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/zhanghandong/rust-skills
Category
Rust

More from zhanghandong/rust-skills

All 34

Recommended

More Rust
1zhanghandong avatarm13-domain-errorzhanghandong/rust-skillsm13 domain error738skills.sh installs
2zhanghandong avatardomain-clizhanghandong/rust-skillsdomain cli709skills.sh installs
3zhanghandong avatardomain-cloud-nativezhanghandong/rust-skillsdomain cloud native596skills.sh installs
4zhanghandong avatardomain-fintechzhanghandong/rust-skillsdomain fintech581skills.sh installs
5zhanghandong avatardomain-mlzhanghandong/rust-skillsdomain ml573skills.sh installs
6nomadamas avatarrhwp-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