type-driven-design-rust
用类型设计更安全的 Rust API
当不变量停留在运行时逻辑中时,Rust API 可能会允许无效状态或误传值。此技能展示如何使用 newtype、typestate、builder、phantom types 和 session types 对不变量进行编码。
使用我的智能体安装
将此请求复制给你的智能体,其中包含权威 Skill 页面和清单。
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.你的智能体仍应展示其计划,并按安全策略请求必要确认。
Agent 可读资源
当 AI Agent、爬虫或脚本需要干净上下文,而不是读取完整页面时,请使用这些链接。
测试它
正在使用“type-driven-design-rust”。 我需要阻止 UserId 和 OrderId 在服务调用中被混用。
预期结果:
- 该技能建议围绕共享标识符表示创建独立的 newtype 包装器。
- 它会解释构造函数、访问器,以及会拒绝错误标识符类型的函数签名。
- 它会指出应在何处实现转换和显示行为。
正在使用“type-driven-design-rust”。 我的请求 builder 允许 POST 请求没有 body。
预期结果:
- 该技能会将 builder 映射为 method 和 body 状态。
- 它会让 send 只在有效状态组合下可用。
- 它会解释为什么无效请求序列会在编译期间失败。
正在使用“type-driven-design-rust”。 我想建模一个带身份验证和事务的数据库会话。
预期结果:
- 该技能会识别会话状态和允许的转换。
- 它按状态分离方法,因此未认证会话无法启动事务。
- 它会描述这种设计的人体工程学和复杂度权衡。
安全审计
安全All 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.
风险因素
⚙️ 外部命令 (33)
分享与引用此报告
分享版本化评估报告、中性徽章、嵌入卡片和引用。Skillstore 只报告证据,不判断该 Skill 是否安全。
复制报告链接
https://skillstore.io/skills/emillindfors-type-driven-design/audits/4?utm_source=security_passport&utm_medium=share&utm_campaign=versioned_reportMarkdown 徽章
[](https://skillstore.io/skills/emillindfors-type-driven-design?utm_source=security_passport_badge)HTML 徽章
<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>嵌入卡片
<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>学术引用 (APA · BibTeX · CFF)
APA 引用
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 引用
@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 评分
评分依据 证据置信度: 高你能构建什么
防止 API 误用
设计库 API,使无效的方法调用顺序和缺失必需值无法通过编译。
建模领域不变量
用不同类型表示标识符、单位和已验证值,而不是共享原始值。
教授更安全的 Rust 模式
通过前后对比示例解释类型层面的技术,展示编译期保证。
试试这些提示
我有用于 [domain meaning] 的 [value type]。展示一个 Rust newtype 设计,用构造函数和使用示例防止值混淆。
将这个 Rust 工作流重构为 typestate API。状态是 [states],允许的转换是 [transitions]。解释编译期保证。
为 [configuration object] 设计一个 Rust builder,其中 [required fields] 必须先设置,build 才可用。包含可选字段和权衡。
为 [protocol] 创建一个 session-type 设计。该协议必须在编译期强制执行 [authentication, transaction, cleanup, or other steps]。
最佳实践
- 从那些只在运行时检查时会导致真实 bug 的不变量开始。
- 保持 marker types 和构造函数小巧,使公共 API 保持可读。
- 清晰解释编译期失败,让调用者理解如何达到有效状态。
避免
- 不要为每个布尔值或次要验证规则都使用 typestate。
- 不要暴露会绕过类型所编码不变量的 unchecked 构造函数。
- 不要在没有示例或类型别名的情况下向用户隐藏复杂的泛型错误。
常见问题
此技能涵盖哪些 Rust 模式?
它能帮助重构现有 Rust API 吗?
该技能会执行 Rust 代码吗?
我什么时候应该避免类型驱动设计?
这对初学者有用吗?
我应该如何将它与 Claude、Codex 或 Claude Code 一起使用?
开发者详情
作者
EmilLindfors许可证
MIT
Skillstore 修订
r1
版本提示
作者未声明版本。
引用
a06681402992ceae98ba04d54cfd4ab004862696
维护新鲜度
2026/7/18
使用量
5 次下载 · 150 次浏览
文件结构
📄 SKILL.md