| name | rust-workflow |
| version | 1.0.0 |
| status | implemented |
| description | Rust 项目工作流增强 - 覆盖 Rust 特有的所有权、生命周期、错误处理模式
自动叠加到 agentic-workflow 上,提供语言专属指导
|
| tags | ["language","rust","workflow"] |
| requires | {"tools":["Bash","Read","Write","Grep"]} |
RUST WORKFLOW
Overview
当检测到 Rust 项目时(存在 Cargo.toml),此 skill 的规则叠加。
项目检测
test -f Cargo.toml && echo "Rust project"
Iron Laws(Rust 专属)
NO unwrap() IN LIBRARY CODE — 只有 main/tests/examples 可用 unwrap(),库代码用 ? 传播
NO UNSAFE WITHOUT COMMENT — unsafe 块必须有安全性注释说明为什么这是安全的
CLIPPY MUST PASS — cargo clippy 必须无 warnings(-D warnings 模式)
NO CLONE TO FIX BORROW — 不能仅为了绕过 borrow checker 而 clone,先理解所有权
EXECUTING 阶段 — Rust 规范
构建与质量检查
cargo build
cargo test
cargo clippy -- -D warnings
cargo fmt --check
错误处理最佳实践
fn read_config(path: &str) -> Result<Config, Box<dyn std::error::Error>> {
let content = std::fs::read_to_string(path)?;
let config: Config = serde_json::from_str(&content)?;
Ok(config)
}
fn read_config(path: &str) -> Config {
let content = std::fs::read_to_string(path).unwrap();
serde_json::from_str(&content).unwrap()
}
所有权常见模式
fn print_name(name: &str) { println!("{name}"); }
fn print_name(name: String) { println!("{name}"); }
fn append_suffix(s: &mut String) { s.push_str("_suffix"); }
DEBUGGING 阶段 — Rust 专属诊断
cargo test -- --nocapture 2>&1 | tail -60
cargo build 2>&1 | head -40
cargo clippy 2>&1 | head -30
rustc --version && cargo --version
常见 Rust 陷阱
| 问题 | 症状 | 修复 |
|---|
| 生命周期不够长 | borrowed value does not live long enough | 检查数据所有者,考虑 Arc<T> |
| 多重可变借用 | cannot borrow as mutable more than once | 分拆借用作用域,或用 RefCell |
| 移动后使用 | value used here after move | 在移动前 clone 或改为借用 |
Send 未实现 | cannot send ... between threads | 用 Arc<Mutex<T>> 包装 |
| 异步 trait 未支持 | the trait cannot be made into an object | 使用 async-trait crate |
REVIEWING 阶段 — Rust 专属清单