m05-type-driven

Design Rust code with newtypes and type state to enforce compile-time invariants.

287|18|Updated Feb 14, 2026
One-click install
npx skills add https://github.com/fjrevoredo/mini-diarium --skill m05-type-driven-fjrevoredo
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: m05-type-driven
Source: https://github.com/fjrevoredo/mini-diarium/tree/main/.agents/skills/m05-type-driven
Command: npx skills add https://github.com/fjrevoredo/mini-diarium --skill m05-type-driven-fjrevoredo

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides guidance on how to use type-driven design techniques to prevent invalid states and improve code safety and expressiveness.

Core Features & Use Cases

  • Type Safety Enhancements: Demonstrates creating newtypes and type state patterns to encode invariants at compile-time.
  • Design Patterns Guide: Explains how to implement phantom types, marker traits, and builders for robust software design.
  • Use Case: A developer wants to ensure only valid user IDs or connection states are possible in their application, reducing runtime errors.

Quick Start

Ask for examples on how to define type-safe wrappers or implement state transitions with types.

Frequently Asked Questions about m05-type-driven

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

FAQPage Schema
How do I use Rust type state patterns to prevent invalid states at compile time?

Rust type state patterns encode state transitions directly into the type system, enforcing compile-time guarantees that prevent invalid states. This technique leverages phantom data and marker traits to make invalid states unrepresentable.

What is the best way to enforce type safety for user IDs and connection states in Rust?

The best way to enforce type safety for user IDs and connections is using newtype patterns. Newtypes create distinct type wrappers around primitive values, ensuring only valid IDs or connection states are accepted and reducing runtime errors.

When do I need phantom data and marker traits in Rust design patterns?

You need phantom data and marker traits when implementing type-driven design patterns that require zero-sized type parameters for compile-time invariant enforcement. They allow you to track type state without runtime overhead.

How do I implement a type-safe builder pattern in Rust for robust software design?

To implement a type-safe builder pattern in Rust, use type state transitions to enforce correct method ordering. The builder enforces invariants at compile-time, ensuring required fields are populated before the final object construction succeeds.

Does type-driven design in Rust work for state machines and invariant enforcement?

Yes, type-driven design in Rust works exceptionally well for state machines and invariant enforcement. By encoding rules into types, the compiler guarantees that only valid state transitions occur, eliminating entire classes of runtime errors.

What are the limitations of using type state patterns in Rust?

Type state patterns in Rust can increase code complexity and boilerplate, potentially making APIs harder to understand. When type signatures become too complex, they may hinder developer ergonomics and require significant compiler overhead.