应该把源代码、示例、文档、单元测试、集成测试、许可证、基准测试等内容放在哪里?
遵循这个标准布局,您将能够使用Cargo的命令轻松构建、运行和测试项目。运行. ├── Cargo.lock ├── Cargo.toml ├── benches │ └── large-input.rs ├── examples │ └── simple.rs ├── src │ ├── bin │ │ └── another_executable.rs │ ├── lib.rs │ └── main.rs └── tests └── some-integration-tests.rs
Cargo.toml
andCargo.lock
are stored in the root of your project.- Source code goes in the
src
directory.- The default library file is
src/lib.rs
.- The default executable file is
src/main.rs
.- Other executables can be placed in
src/bin/*.rs
.- Integration tests go in the
tests
directory (unit tests go in each file they're testing).- Example executable files go in the
examples
directory.- Benchmarks go in the
benches
directory.These are explained in more detail in the manifest description.
cargo new
来设置一个新的可执行项目或者cargo new --lib
来设置一个新的库项目。///
开头的注释,或者用//!
来记录父项)。此外,许可证通常放在根目录下。cargo new --lib
生成新库时Cargo生成的内容):#[cfg(test)]
mod tests {
#[test]
fn it_works() {
}
}