包布局
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 如何自动推断目标名称的更多信息,请参阅 目标自动发现。