AgentLint 实测验证 100/100基于 211 个 Rust 开源仓库统计

    Rust CLAUDE.md & AGENTS.md 模板

    单 crate 秒级 cargo check、严格 Clippy 门禁与零 .unwrap() 纪律,提炼自 211 个 Rust 仓库(含 uv 与 ruff)。

    # Rust Project — Rust Workspace Harness
    
    Rust workspace organized into focused crates with Clippy warnings denied in CI.
    
    ## Commands
    
    - Fast compile check: `cargo check -p <crate>`
    - Fast single test: `cargo test -p <crate> <test_name>`
    - Full workspace tests: `cargo test --workspace`
    - Lint & format: `cargo clippy --workspace --all-targets -- -D warnings && cargo fmt --check`
    
    ## Rules
    
    - Don't use `.unwrap()` or `.expect()` in library or production request paths. Instead propagate errors with `?` and structured `thiserror` variants. Because panics crash worker threads under unexpected input.
    - Don't run `cargo test --workspace` after every small edit. Instead run `cargo test -p <crate> <test_name>`. Because workspace builds add minutes to every iteration.
    - Don't suppress Clippy lints with `#[allow(...)]` without a one-line comment explaining the invariant.
    - When changing serialization formats or CLI flags, read `docs/compatibility.md`.
    
    ## Continuity & Safety
    
    - Never commit credentials, local `target/` artifacts, or `CLAUDE.local.md`.
    - Document crate-level design decisions in `HANDOFF.md`.

    Rust 开源生态中最常采用的工程规则

    基于 4,533 仓库研究中 211 个公开 Rust 仓库的实测统计:

    cargo-test测试

    Use cargo test

    57.8%122 个仓库
    clippy工具链

    Use clippy for linting

    56.4%119 个仓库
    cargo-fmt工具链

    Use cargo fmt / rustfmt for formatting

    46.9%99 个仓库
    error-handling代码规范

    Proper error handling with context

    45.0%95 个仓库
    unit-tests测试

    Write unit tests for all changes

    42.7%90 个仓库
    integration-tests测试

    Integration tests in tests/ directory

    34.6%73 个仓库
    tokio工具链

    Tokio async runtime

    34.1%72 个仓库
    error-handling-result代码规范

    Use Result<T, E> for error handling

    33.6%71 个仓库
    必写验证命令(对应规则 W1 与 W7)
    安装依赖
    cargo fetch
    快速单测(秒级迭代)
    cargo test -p <crate> <test_name> -- --nocapture
    全量测试
    cargo test --workspace
    Lint 与静态检查
    cargo clippy --workspace --all-targets -- -D warnings && cargo fmt --check
    生产构建
    cargo build --workspace
    Rust 项目中 AI 代理常见踩坑
    • 01AI 为了绕过借用检查器随手加 .unwrap() 和多余 .clone()。
    • 02在大型 workspace 每次小改动都跑 cargo test --all-features 耗时 10 分钟以上,必须写明 -p <crate>。

    更多实证验证模板