# m05-type-driven

This skill helps shape Rust types so invalid states can be rejected by the compiler. Use it for newtypes, type-state APIs, and checked builders.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 3400 installs · ★ 1545
- Author: actionbook
- License: not stated · policy=link-only · description only; the file stays with the author
- Source: https://github.com/actionbook/rust-skills/tree/HEAD/skills/m05-type-driven/SKILL.md
- Updated: 2026-08-23
- HTML: https://affpapa.org/en/nevibecode/skills/m05-type-driven

## What it does

m05-type-driven frames type-driven design around one question: can a constraint live in the type system instead of a runtime check? It covers newtypes for semantic values, type state for state transitions, PhantomData, marker traits, builders, sealed traits, and zero-sized marker types.

The skill maps common design needs to patterns. A primitive wrapper handles type safety, a type parameter can encode a valid state, and a builder can control gradual construction. Its examples include `Connection<Connected>`, `PhantomData<T>`, and a private sealed trait that blocks outside implementations.

For a Rust project, that is a reason to inspect invariants before adding runtime validation. Public fields can let callers break those invariants, while `Option` may leave initialization state unclear. The skill is available for Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, and OpenCode.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add actionbook/rust-skills --skill m05-type-driven -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/m05-type-driven/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/m05-type-driven/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add actionbook/rust-skills --skill m05-type-driven -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/m05-type-driven/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add actionbook/rust-skills --skill m05-type-driven -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/m05-type-driven/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install actionbook/rust-skills m05-type-driven
```

2. **Manually: put the files in place**
- File: `.github/skills/m05-type-driven/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add actionbook/rust-skills --skill m05-type-driven -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/actionbook/rust-skills --path skills/m05-type-driven
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/m05-type-driven/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add actionbook/rust-skills --skill m05-type-driven -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/actionbook/rust-skills/tree/HEAD/skills/m05-type-driven/SKILL.md

## When to use it
- encode an invariant in a type
- separate object states at compile time
- wrap a primitive in a semantic newtype
- construct an API with a typed builder
- prevent external trait implementations

## Example prompts
- Design `Email` as a validated newtype and show where construction should validate it.
- Model `Connection` with type states for `Disconnected` → `Connected` → `Authenticated`.
- Review this Rust API and replace runtime checks with a suitable newtype, `PhantomData`, marker trait, or builder.

## Similar
- [python-type-safety](https://affpapa.org/en/nevibecode/skills/python-type-safety.md) — skill · 12643 installs
- [principle-type-system-discipline](https://affpapa.org/en/nevibecode/skills/principle-type-system-discipline.md) — skill · 5300 installs
- [type-design-performance](https://affpapa.org/en/nevibecode/skills/type-design-performance.md) — skill · 655 installs
- [122-java-type-design](https://affpapa.org/en/nevibecode/skills/122-java-type-design.md) — skill · 394 installs
- [auto-type-checking](https://affpapa.org/en/nevibecode/skills/auto-type-checking.md) — skill · 435 installs
- [test-driven-development](https://affpapa.org/en/nevibecode/skills/test-driven-development.md) — skill · 259292 installs

From the same set: [actionbook/rust-skills](https://affpapa.org/en/nevibecode/by/actionbook/rust-skills.md) — 33 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
