type-driven-design-rust
Design Safer Rust APIs with Types
Rust APIs can allow invalid states or swapped values when invariants stay in runtime logic. This skill shows how to encode invariants with newtypes, typestate, builders, phantom types, and session types.
Install with my Agent
Copy this request to your Agent. It includes the canonical Skill page and manifest.
Review the Skillstore skill "type-driven-design-rust" from https://skillstore.io/skills/emillindfors-type-driven-design.md and its manifest at https://skillstore.io/api/skills/emillindfors-type-driven-design/manifest. Verify the artifact. You may proceed after verification, subject to the environment's own policy.Your Agent should still show its plan and request any confirmation required by the security policy.
Agent-readable resources
Use these links when an AI agent, crawler, or script needs clean context instead of reading the full page.
Test it
Using "type-driven-design-rust". I need to stop UserId and OrderId from being mixed in service calls.
Expected outcome:
- The skill recommends separate newtype wrappers around the shared identifier representation.
- It explains constructors, accessors, and function signatures that reject the wrong identifier type.
- It notes where conversions and display behavior should be implemented.
Using "type-driven-design-rust". My request builder allows POST requests without a body.
Expected outcome:
- The skill maps the builder into method and body states.
- It makes send available only for valid state combinations.
- It explains why invalid request sequences fail during compilation.
Using "type-driven-design-rust". I want to model a database session with authentication and transactions.
Expected outcome:
- The skill identifies session states and allowed transitions.
- It separates methods by state so unauthenticated sessions cannot start transactions.
- It describes the ergonomics and complexity trade-offs of this design.
Security Audit
SafeAll static findings were adjudicated as false positives. The backtick detections are Markdown code fences, the URLs are examples or documentation links, and the reconnaissance matches are benign Rust type-design text.
Risk Factors
โ๏ธ External commands (33)
๐ Network access (6)
Share & cite this report
Share the versioned assessment report, neutral badge, embed card, and citations. Skillstore reports evidence without deciding whether this Skill is safe.
Copy report link
https://skillstore.io/skills/emillindfors-type-driven-design/audits/4?utm_source=security_passport&utm_medium=share&utm_campaign=versioned_reportMarkdown badge
[](https://skillstore.io/skills/emillindfors-type-driven-design?utm_source=security_passport_badge)HTML badge
<a href="https://skillstore.io/skills/emillindfors-type-driven-design?utm_source=security_passport_badge"><img src="https://skillstore.io/badges/skills/emillindfors-type-driven-design/security.svg" alt="Skillstore security assessment" loading="lazy"></a>Embed card
<iframe src="https://skillstore.io/embed/skills/emillindfors-type-driven-design.html" title="Skillstore Security Assessment" sandbox="allow-popups allow-popups-to-escape-sandbox" loading="lazy" referrerpolicy="no-referrer" width="420" height="180"></iframe>Academic citations (APA ยท BibTeX ยท CFF)
APA citation
EmilLindfors. (2026). type-driven-design-rust security audit report (audit version 4) [Author version unspecified]. Skillstore. https://skillstore.io/skills/emillindfors-type-driven-design/audits/4BibTeX citation
@techreport{emillindfors-emillindfors-type-driven-design-2026,
author = {EmilLindfors},
title = {type-driven-design-rust security audit report (audit version 4)},
institution = {Skillstore},
year = {2026},
number = {4},
url = {https://skillstore.io/skills/emillindfors-type-driven-design/audits/4},
note = {Author version unspecified}
}CITATION.cff
cff-version: 1.2.0
message: "If you use this Skill, cite its author and this versioned security audit report."
title: "type-driven-design-rust security audit report (audit version 4)"
version: "unspecified"
type: report
authors:
- name: "EmilLindfors"
date-released: "2026-07-06"
url: "https://skillstore.io/skills/emillindfors-type-driven-design/audits/4"
identifiers:
- type: other
value: "skillstore:emillindfors-type-driven-design:audit:4"
description: "Skillstore immutable audit report identifier"
Skillstore Score
Why this score Evidence Confidence: HighWhat You Can Build
Prevent API Misuse
Design library APIs that make invalid method order and missing required values impossible to compile.
Model Domain Invariants
Represent identifiers, units, and validated values with distinct types instead of shared primitive values.
Teach Safer Rust Patterns
Explain type-level techniques with before-and-after examples that show compile-time guarantees.
Try These Prompts
I have [value type] used for [domain meaning]. Show a Rust newtype design that prevents value mix-ups, with constructors and usage examples.
Refactor this Rust workflow into a typestate API. The states are [states], and the allowed transitions are [transitions]. Explain the compile-time guarantees.
Design a Rust builder for [configuration object] where [required fields] must be set before build is available. Include optional fields and trade-offs.
Create a session-type design for [protocol]. The protocol must enforce [authentication, transaction, cleanup, or other steps] at compile time.
Best Practices
- Start with invariants that cause real bugs when they are only checked at runtime.
- Keep marker types and constructors small so the public API stays readable.
- Explain compile-time failures clearly so callers understand how to reach valid states.
Avoid
- Do not use typestate for every boolean or minor validation rule.
- Do not expose unchecked constructors that bypass the invariant encoded by the type.
- Do not hide complex generic errors from users without examples or type aliases.
Frequently Asked Questions
What Rust patterns does this skill cover?
Can it help refactor an existing Rust API?
Does the skill execute Rust code?
When should I avoid type-driven design?
Is this useful for beginners?
How should I use it with Claude, Codex, or Claude Code?
Developer Details
Author
EmilLindforsLicense
MIT
Skillstore revision
r1
Version notice
The author did not declare a version.
Ref
a06681402992ceae98ba04d54cfd4ab004862696
Maintenance freshness
7/18/2026
Usage
5 downloads ยท 150 views
File structure
๐ SKILL.md