Package layout
Được mô tả trong Cargo book, một crate trong Rust sẽ có layout như sau:
.
├── Cargo.lock
├── Cargo.toml
├── src/
│ ├── lib.rs
│ ├── main.rs
│ ├── helper.rs
│ ├── utils/
│ │ ├── mod.rs
│ │ └── math.rs
│ └── bin/
│ ├── named-executable.rs
│ └── another-executable.rs
├── benches/
│ ├── large-input.rs
│ └── multi-file-bench.rs
├── examples/
│ ├── simple.rs
│ └── complex.rs
└── tests/
├── some-integration-tests.rs
└── multi-file-test/
├── main.rs
└── test_module.rs
Cargo.tomlvàCargo.lockdược đặt ở thư mục gốc của package. Thường để sử dụng các library nào đó, người ta sẽ hướng dẫn bạn thêm một dòng ví dụlog = "0.6"bên dưới section[dependencies]hoặc[dev-dependencies]. Không nên đụng đến fileCargo.lockdo nó được generate tự động.- Source code được đặt trong thư mục
src. - File chính của library crate là
src/lib.rs. - File chính của binary crate là
src/main.rs. - Benchmark code được đặt trong thư mục
benches. - Code ví dụ (examples) được đặt trong thư mục
examples. - Integration tests được đặt trong thư mục
tests. helper.rsvàutils/được gọi là các module. Nếu module là một thư mục gồm nhiều file khác, filemod.rsđược coi như là file index của module đó. Xem thêm về modules tại đây.