actionbook avatar

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
View on GitHub

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

Installs 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

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

Details

Repository
github.com/actionbook/rust-skills
Category
Rust
First seen
May 16, 2026

More from actionbook/rust-skills

All 38

Similar to M05 Type Driven

More Rust