rust-development
为去中心化项目应用 Rust 最佳实践
构建去中心化基础设施需要特别关注内存安全、错误处理和异步模式。此技能提供经过验证的 Rust 开发指南,专为基于 commonware 的项目(如 Guts)量身定制,确保代码安全且符合习惯用法。
下载技能 ZIP
在 Claude 中上传
前往 Settings → Capabilities → Skills → Upload skill
开启并开始使用
Agent 可读资源
当 AI Agent、爬虫或脚本需要干净上下文,而不是读取完整页面时,请使用这些链接。
测试它
正在使用“rust-development”。 为仓库模块创建错误类型
预期结果:
- 定义一个实现 thiserror::Error 的枚举
- 使用 #[error("...")] 宏提供用户友好的消息
- 为自动错误转换添加 #[from] 属性
- 创建公共的 Result<T> 类型别名
- 示例:NotFound、PermissionDenied、Storage 变体
正在使用“rust-development”。 使用 Tokio 设置新的 Guts 服务
预期结果:
- 创建带有 mpsc::Sender<Command> 的 Service 结构体
- 使用 oneshot 通道实现异步方法以获取响应
- 使用取消令牌添加关闭信号
- 使用 tokio::select! 处理多个任务
- 在 Cargo.toml 中配置 clippy 以拒绝警告
正在使用“rust-development”。 使用 Ed25519 签名进行身份验证
预期结果:
- 使用 Ed25519::generate() 生成密钥对
- 实现返回 Signature 的 sign(message) 方法
- 使用 Verifier trait 验证签名
- 在 Identity 结构体中安全存储密钥对
- 与 commonware-cryptography crate 集成
安全审计
低风险Static analysis reported many command, network, sensitive-file, weak-crypto, reconnaissance, and heuristic issues. Review found these are Markdown examples, Rust identifiers, Cargo metadata, and legitimate development guidance, with no evidence of malicious intent or prompt injection.
已确认安全问题 (1)
能力复核项 (3)
这些是真实的本地能力,对此技能可能是预期行为,因此需要复核,但不会按已确认恶意行为计分。
风险因素
⚙️ 外部命令 (1)
🌐 网络访问 (1)
质量评分
你能构建什么
学习去中心化 Rust 模式
了解如何使用 commonware 原语为 P2P 网络和 BFT 共识编写安全、惯用的 Rust 代码
遵循 Guts 项目约定
在 Guts 代码库中保持一致的代码风格、错误处理和模块结构
应用异步模式和错误处理
学习使用 Tokio 通道的结构化并发以及为可靠分布式系统设计适当的错误类型
试试这些提示
Review this Rust code for the Guts project. Check if it follows idiomatic Rust patterns, proper error handling with thiserror, and structured concurrency with Tokio.
Design error types using thiserror for a new module in Guts. Include From implementations for underlying storage and network errors.
Show me how to integrate commonware-cryptography or commonware-p2p into a Guts service. Include proper initialization and error handling.
Design an async service using Tokio with structured concurrency. Include channel-based command handling, oneshot responses, and shutdown signaling.
最佳实践
- 在每次提交前运行 cargo fmt 和 cargo clippy 以保持代码质量
- 对库错误使用 thiserror,对应用程序级错误使用 anyhow
- 优先使用 Tokio 通道而非共享可变状态进行任务间通信
避免
- 避免使用 unsafe 代码,除非对于 FFI 或性能绝对必要
- 不要忽略 clippy 警告 - 将它们视为编译错误
- 避免在异步上下文中使用 .wait() 或同步 I/O 阻塞异步代码