m05-type-driven

Encode Rust type-system invariants to prevent invalid runtime states.

1|Updated May 29, 2026
One-click install
npx skills add https://github.com/simorgh3196/tsuzulint --skill m05-type-driven
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: m05-type-driven
Source: https://github.com/simorgh3196/tsuzulint/tree/main/.agents/skills/m05-type-driven
Command: npx skills add https://github.com/simorgh3196/tsuzulint --skill m05-type-driven

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps developers prevent invalid runtime states by encoding invariants in the Rust type system, enabling compile-time guarantees that certain states can only exist when preconditions are met.

Core Features & Use Cases

  • Type State: model distinct states with separate types to ensure valid transitions at compile time.
  • Newtype: wrap primitive values to enforce domain semantics and invariants.
  • PhantomData: use phantom type parameters to encode additional constraints without runtime cost.
  • Marker Traits: express capabilities and allowed operations through trait bounds.
  • Builder Pattern: progressively construct complex objects with type-safe steps.
  • Sealed Trait / ZST: limit external implementations and leverage zero-sized markers for safety and API clarity.

Quick Start

Create a small Rust module that defines a newtype around a primitive (e.g., UserId), implements a simple Type State flow (e.g., Unregistered -> Registered), and experiments with PhantomData and marker traits to encode invariants. Then wire a minimal builder to demonstrate gradual construction.

Frequently Asked Questions about m05-type-driven

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

FAQPage Schema
How do I prevent invalid state transitions in Rust at compile time?

To prevent invalid state transitions in Rust at compile time, encode your invariants using the type-state pattern, modeling distinct states as separate types so the compiler rejects invalid transitions.

What is the best way to enforce domain semantics on primitive values in Rust?

The best way to enforce domain semantics on primitive values in Rust is the newtype pattern, wrapping primitives in dedicated structs to guarantee type safety and prevent invalid runtime data.

How does PhantomData work to encode constraints in Rust without runtime cost?

PhantomData works by using phantom type parameters to encode additional compile-time constraints in Rust, enforcing invariants and relationships between types without incurring any runtime cost.

How do I build a type-safe builder pattern for complex Rust objects?

To build a type-safe builder pattern in Rust, progressively construct complex objects using type-state steps and marker traits, ensuring required fields are initialized before compilation succeeds.

Can I use marker traits to express allowed operations in Rust API design?

Yes, you can use marker traits in Rust API design to express capabilities and allowed operations through trait bounds, ensuring certain functions are only callable on types that meet specific criteria.

When should I use sealed traits and zero-sized types in Rust?

Use sealed traits and zero-sized types in Rust when you need to limit external implementations of your APIs and leverage zero-sized markers for safety and clarity without runtime overhead.