rust-type-driven
CommunityEncode Rust invariants in types.
Authorhuiali
Version1.0.0
Installs0
System Documentation
What problem does it solve?
This Skill helps Rust developers prevent runtime errors by encoding domain-specific rules and invariants directly into their types, making invalid states unrepresentable and ensuring compile-time safety.
Core Features & Use Cases
- Newtype Pattern: Create distinct types for values with the same representation but different semantics (e.g.,
UserIdvs.OrderId). - Type State Pattern: Encode state machines where transitions are enforced by the type system, preventing invalid operations.
- Builder Pattern with Type State: Construct complex objects with compile-time guarantees for required fields.
- PhantomData: Mark ownership and variance for zero-cost abstractions.
- Zero-Sized Types (ZST): Use types with no runtime cost for compile-time markers and abstractions.
- Use Case: Prevent accidental mixing of
UserIdandOrderIdby using distinctUserIdandOrderIdnewtypes, ensuring type safety at compile time.
Quick Start
Use the rust-type-driven skill to demonstrate the newtype pattern for user and order IDs in Rust.
Dependency Matrix
Required Modules
None requiredComponents
scriptsreferences
💻 Claude Code Installation
Recommended: Let Claude install automatically. Simply copy and paste the text below to Claude Code.
Please help me install this Skill: Name: rust-type-driven Download link: https://github.com/huiali/rust-skills/archive/main.zip#rust-type-driven Please download this .zip file, extract it, and install it in the .claude/skills/ directory.
Agent Skills Search Helper
Install a tiny helper to your Agent, search and equip skill from 223,000+ vetted skills library on demand.