## Rust测试项目 ### 基础使用 项目依赖在 Cargo.toml 各种轮子库 [crates.io](https://crates.io) 各种轮子库文档 [docs.rs](https://docs.rs/) **创建项目** > cargo new <项目名> 加 --lib 参数创建库项目,加 --vcs none 不初始化本地git仓库 默认是 --bin 和初始化 .git **下载依赖和构建项目** > cargo build 加 --release 参数开启优化,并将编译结果输出到 target/release 目录 默认是 --debug 和输出到 target/debug 目录 **运行** 如果未构建则先构建 > cargo run **测试** > cargo test **为项目构建文档** > cargo doc **将库发布到crates.io** > cargo publish 更多cargo工具链说明参考 [Cargo 中文文档](https://cargo.budshome.com/index.html) ### 加国内镜像 > vim ~/.cargo/config ``` [source.crates-io] registry = "https://github.com/rust-lang/crates.io-index" replace-with = 'ustc' [source.ustc] registry = "git://mirrors.ustc.edu.cn/crates.io-index" ```