plugins/languages/rust/skills/core/SKILL.md
Rust 核心开发规范 — Edition 2024 / Rust 1.85+、所有权三原则、Result/Option/? 错误处理、thiserror + anyhow、let-else、if-let-chains、async fn in traits、cargo / clippy / rustfmt / nextest 工具链。所有 Rust 编码、调试、测试、性能优化任务的前置基线规范,其他 rust 系列 skill 的共同前提。触发短语:写 Rust、Rust 项目结构、Cargo.toml、错误处理、clippy 报错、cargo lint、Rust 规范、Rust best practices、Rust 2024。
npx skillsauth add lazygophers/ccplugin rust-coreInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
声明式标准,加载即视为本会话所有 Rust 代码生成、修改、评审的硬约束。
async fn in traits 全部 stable)。Cargo.toml 必须 edition = "2024" 且声明 rust-version。&T 或唯一一个 &mut T,二者互斥。Drop。thiserror 2.x 定义类型化错误枚举,公共 API 暴露具体错误类型,禁止 Box<dyn Error> 出现在公共签名。anyhow 1.x + .context("...") 附加上下文。#[error(transparent)] #[from] 透传第三方错误。.unwrap() / .expect() 处理可恢复错误;测试和 const 上下文除外,且必须有 expect("<reason>") 文字理由。? 而非 match 手动展开;用 let-else 替代 if let Some(x) = ... else { return Err(...) }。use thiserror::Error;
#[derive(Error, Debug)]
pub enum AppError {
#[error("not found: {0}")] NotFound(String),
#[error("invalid input: {0}")] InvalidInput(String),
#[error(transparent)] Io(#[from] std::io::Error),
}
| 用途 | 选型 |
|------|------|
| 异步运行时 | tokio 1.x(默认) |
| HTTP 服务 | axum 0.8+(基于 tower) |
| HTTP 客户端 | reqwest |
| 序列化 | serde + serde_json / toml |
| 日志 | tracing + tracing-subscriber |
| 错误 | thiserror 2.x / anyhow 1.x |
| 数据库 | sqlx(编译时检查)/ sea-orm / diesel |
| CLI | clap 4.x(derive feature) |
| 测试 | cargo-nextest + proptest + criterion |
| 数据并行 | rayon |
| 字节零拷贝 | bytes |
cargo fmt --check
cargo clippy --all-targets -- -W clippy::all -W clippy::pedantic -D warnings
cargo nextest run # 优先于 cargo test
cargo audit # 依赖漏洞
cargo deny check # 许可证 + ban 列表
// let-else
let Some(id) = input.strip_prefix("id:") else {
anyhow::bail!("invalid format");
};
// if-let-chains
if let Some(u) = get_user(id) && u.is_active && u.role == Role::Admin {
grant_access(&u);
}
// async fn in traits(禁用 #[async_trait])
trait Repo: Send + Sync {
async fn get(&self, id: u64) -> anyhow::Result<Option<Row>>;
}
my-crate/
├── Cargo.toml # edition = "2024", rust-version = "1.85"
├── src/
│ ├── lib.rs # 库入口
│ ├── main.rs # bin 入口(可选)
│ ├── error.rs
│ └── domain/
├── tests/ # 集成测试
├── benches/ # criterion 基准
├── examples/
└── .cargo/config.toml
单文件硬限:.rs ≤ 600 行,推荐 200~400 行;超限拆模块。
多 crate 项目用 workspace + [workspace.dependencies] 统一版本,子 crate 引用 tokio.workspace = true。
| AI 倾向 | 正确做法 |
|---------|---------|
| unwrap() 临时凑数 | ? 或带原因的 expect |
| clone() 绕开借用 | 优先借用 / Cow / 移动 |
| String 入参 | &str / impl AsRef<str> |
| #[async_trait] | 直接 async fn in trait |
| Box<dyn Error> 公共 API | thiserror 类型化错误 |
| cargo test | cargo nextest run |
cargo fmt --check 通过cargo clippy ... -D warnings 零警告/// 文档Cargo.toml edition / rust-version 已声明cargo audit & cargo deny check 通过rust-memory — 借用 / 生命周期 / 智能指针rust-async — Tokio / async fn in traits / towerrust-unsafe — unsafe 最小化 / MIRI / FFIrust-macros — macro_rules! / proc-macrotools
--- name: trellisx-workspace description: 维护 `.trellis/task.md` 任务看板 —— trellis 缺的跨任务总览。**一个表格, 一行一个任务**, 列为 id/名称/描述/状态/阶段/进度/worktree (状态/阶段中文显示)。在 task create/start/阶段切换/archive 后**及时更新**对应行; 并**自动清理超 7 天的已完成行**防膨胀。保持看板与 task.json 实时一致。 when_to_use: 维护 / 创建 / 更新 `.trellis/task.md` 任务看板时; task 生命周期任一节点 (create/start/阶段推进/archive) 之后同步看板时; 用户问"当前有哪些任务 / 任务进度 / 任务看板"时。被 trellisx-flow 与 trellisx-apply 注入的流程引用。 user-invocable: true argument-hint: [show|update|sync|cleanup ...] [task id] arguments:
testing
强制以 Trellis task 闭环处理用户指定的请求 (自判新建/并入 → plan→exec→check→finish 全程不跳步)。**仅用户显式主动调用** (/trellisx-flow 或明确要求"强制走 task 处理这个"); **禁止自动 / 被动 / 推断式调用** —— 不要因为某个请求"看起来该建 task"就自动触发本 skill, 那是 apply 注入的 no_task 倾向的职责。
testing
把 强推task + subtask拆分 + worktree隔离 + 闭环收尾 四维度增量注入当前项目 .trellis/ (workflow.md 的 no_task/planning/in_progress 块 + spec 背书文档 + trellis 生命周期 hook worktree 自动化)。强推 task 与闭环为纯 prompt 软约束 (非平台 hook 硬拦截)。**纯增量追加, 绝不替换 trellis 原生文本** (no_task 分类+征同意/check/finish/前缀全保留)。幂等 (marker 包裹)。
development
Claude Code 会话历史整理 — 扫 ~/.claude/projects/**/*.jsonl 全部 session transcripts, 提取学习增量 (用户校正/决策/踩坑/L0 规则) → 全局记忆库 ~/.cortex/.wiki/memory/. 默认 --apply 落盘 (--dry-run opt-in 仅出 JSON plan 预览). 与 cortex-extract (L4-inbox 内部) 互补.