m05-type-driven

Encode Rust type system constraints to eliminate invalid runtime states.

Updated Feb 12, 2026
One-click install
npx skills add https://github.com/jmduea/emotiv-cortex-rs --skill m05-type-driven-jmduea
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: m05-type-driven
Source: https://github.com/jmduea/emotiv-cortex-rs/tree/main/.github/skills/m05-type-driven
Command: npx skills add https://github.com/jmduea/emotiv-cortex-rs --skill m05-type-driven-jmduea

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Many Rust codebases rely on runtime checks or loosely typed primitives, leading to bugs that could have been caught at compile time. This Skill helps you redesign APIs so that invalid states are unrepresentable, using patterns like newtype, type state, phantom data, and sealed traits.

Core Features & Use Cases

  • Newtype wrappers to give semantic meaning and validation to primitive values.
  • Type State pattern to encode valid state transitions in the type system.
  • PhantomData and marker traits for zero‑cost compile‑time guarantees.
  • Builder pattern to construct complex objects without exposing invalid intermediate states.
  • Sealed traits to prevent external implementations and maintain API invariants. Use these patterns when designing domain models, networking protocols, or any API where safety and correctness are critical.

Quick Start

Ask the skill to demonstrate redesigning a simple Connection struct using the type‑state pattern.

Frequently Asked Questions about m05-type-driven

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I eliminate invalid runtime states in Rust using the type system?

The Rust type-state pattern encodes valid state transitions in the type system, ensuring invalid states are unrepresentable at compile time. You apply it to structs like Connection by moving runtime checks into type transitions.

What is the Rust type-state pattern and when should I use it?

The Rust type-state pattern encodes valid state transitions in the type system, ensuring invalid states are unrepresentable at compile time. You apply it to structs like Connection by moving runtime checks into type transitions.

How do I use the builder pattern in Rust to prevent invalid intermediate states?

Use the builder pattern to construct complex objects without exposing invalid intermediate states. It enforces compile-time validation by ensuring all required fields are populated before returning a valid instance.

Do I need to understand Rust generics and lifetimes to use type-driven design?

Yes, implementing compile-time validation with type-driven patterns requires knowledge of Rust generics, lifetimes, and trait design to properly apply newtype and type-state techniques.

Why use sealed traits in Rust API design?

Sealed traits in Rust prevent external implementations and maintain API invariants. They ensure downstream users cannot implement your traits, preserving compile-time safety guarantees within your domain models.