包布局
Cargo 使用了文件放置约定,以便于快速理解新的 Cargo 包。
.
├── Cargo.lock
├── Cargo.toml
├── src/
│ ├── lib.rs
│ ├── main.rs
│ └── bin/
│ ├── named-executable.rs
│ ├── another-executable.rs
│ └── multi-file-executable/
│ ├── main.rs
│ └── some_module.rs
├── benches/
│ ├── large-input.rs
│ └── multi-file-bench/
│ ├── main.rs
│ └── bench_module.rs
├── examples/
│ ├── simple.rs
│ └── multi-file-example/
│ ├── main.rs
│ └── ex_module.rs
└── tests/
├── some-integration-tests.rs
└── multi-file-test/
├── main.rs
└── test_module.rs
Cargo.toml和Cargo.lock存储在你的包的根目录下(包根目录)。- 源代码放在
src目录下。 - 默认的库文件是
src/lib.rs。 - 默认的可执行文件是
src/main.rs。- 其他可执行文件可以放在
src/bin/中。
- 其他可执行文件可以放在
- 基准测试文件放在
benches目录下。 - 示例文件放在
examples目录下。 - 集成测试文件放在
tests目录下。
如果二进制文件、示例、基准测试或集成测试包含多个源文件,请将 main.rs 文件以及额外的 模块 放在 src/bin、examples、benches 或 tests 目录的子目录中。可执行文件的名称将是该子目录的名称。
你可以在书中了解更多关于 Rust 模块系统的信息。
有关手动配置目标的更多详细信息,请参见配置目标。有关控制 Cargo 如何自动推断目标名称的更多信息,请参见目标自动发现。