用途:为 Rust 项目提供常用工具链命令参考,覆盖构建、测试、检查、格式化、依赖管理、文档和交叉编译等日常开发环节。
主要能力:构建与运行方面有 cargo build、cargo build --release、cargo run 及带参数的 cargo run -- --arg1 value1。测试方面支持 cargo test,并可通过 cargo test -- --nocapture 显示标准输出、按名称运行指定测试、用 --lib 只跑库测试、用 --doc 只跑文档测试。检查方面提供 cargo check 与 cargo check --all-targets,用于比 build 更快的编译错误检查。代码质量方面使用 cargo clippy -- -W clippy::all 与 cargo clippy --fix 自动修复建议;格式化使用 cargo fmt,CI 中可用 cargo fmt -- --check 只校验不改动。
使用方式:依赖管理包括 cargo add serde --features derive、cargo add tokio --features full、cargo remove unused-crate、cargo update 更新 Cargo.lock、cargo tree 查看依赖树、cargo audit 做安全审计。文档使用 cargo doc --open 或 cargo doc --no-deps,基准测试使用 cargo bench。交叉编译需先用 rustup target add x86_64-unknown-linux-musl 添加目标,再执行 cargo build --release --target x86_64-unknown-linux-musl。工作区场景可用 cargo build --workspace、cargo test --workspace,或 cargo build -p my-crate 指定单个 crate。
适用场景:本地开发、持续集成、代码审查前检查、依赖升级与多目标平台构建。
限制:资料未提供版本要求、安装步骤、平台差异或权限配置等细节;实际行为取决于本地 Rust 与 Cargo 环境。