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
UI/UX 与布局设计——做界面布局/结构/导航/组件/交互的设计决策。触发:做UI/UX/布局/排版/导航/组件/交互/栅格/响应式/图表选型/字体配对。按媒介路由 HTML/Web、原生 App(iOS/Android/桌面)、CLI、TUI。需后端动态系统不适用;配色/主题/色板走姊妹 skill design-color。
tools
主题与配色设计——做颜色搭配/调色板/主题/品牌色阶/暗模式的设计决策。触发:选配色/调色/主题/色板/品牌色/暗模式/对比度/色盲/UI风格。按媒介路由 HTML/Web(CSS变量)、原生App(平台token)、CLI(ANSI)、TUI(真彩/256/16降级)。保证可访问性(对比度/色盲安全)。需后端动态系统不适用;UI/UX 布局/组件/交互走姊妹 skill design-uiux。
tools
跨任意组件(plugin/skill/agent/command)的验证驱动优化循环纪律 skill。当用户要优化某个已有组件却无明确方向、或要防止改了反而更差(自评乐观偏差 / 多维同改归因失效 / 为凑分加废话膨胀)、或要把一套通用「评分→单变量改→改后验证严格更好才留否则回滚→触顶停」的纪律套到任意组件上时使用。管优化过程本身的纪律(validation gate / ratchet / 独立验证 / 触顶停),不评单组件深度(交 skill-dev),不查插件接线(交 plugin-dev)。仅手动 /optimize-any 触发。
data-ai
两层规则记忆 (基于 .skein/spec)。planning 时 recall 召回相关规则、task finish 后 sediment 沉淀学习 + prune 自动精简过期/重复/断链规则。core 常驻硬规 + recall 按需召回, 经判定门自动写盘 (不逐次问用户)。产出 .skein/spec 下 core/recall 规则文件 + index。另支持空仓 bootstrap 播种规则基线、记忆大面积失效 (大重构/换栈) 时 reconstruct 可逆归档后按项目类型分型重建、maintain 手动体检 (超预算/stale/断链/重复/废弃, --apply 自动修复)、auto-fix (Stop hook 写 .pending-fix 标记 → main 派 skein-specer bg 跑 maintain --apply 全自动修, 断链只报告)。