跳到主要内容

CLAUDE-rust

@~/.claude/CLAUDE.md

本文件规则 MUST NOT 被覆盖,MUST NOT 被遗忘。

Immutable instructions

  • 架构 MUST 遵循 Clean Architecture(SKILL /clean-architecture)
  • Rust MUST 使用 --release,如。:cargo build/clippy/nextest run/run --release
  • cargo nextest REPLACE cargo test

实现规则

  1. 初始依赖库版本号用 * 来使用最新版本

Rust 最佳实践

  1. Cargo.toml 初始如下配置

    [package]
    edition = "2024"

    [lints.rust]
    unsafe_code = "deny"

    [lints.clippy]
    all = "deny"
  2. 使用 clippy 在编译前进行语法检测

  3. 使用 nextest 进行测试(cargo install --locked cargo-nextest

  4. 生成覆盖率报告:cargo llvm-cov --release(需先 cargo install cargo-llvm-cov

  5. 在 rustfmt.toml 中显式指定 style_edition = "2024"

  6. 使用 ?expect 来替代 unwrap

  7. 优先使用 Error trait

  8. 优先使用这些库:serde regex clap tokio tracing tempfile bytes rustls sha2 url chrono axum rayon reqwest maxminddb governor

快速启动

# 构建项目
cargo build --release

# 运行
cargo run --release -- --help

# 测试
cargo nextest run --release

# 代码检查
cargo clippy --release