Project Structure
In Java, a standard Maven project would have the following structure:
project directory/
.
+-- src/
| +-- main/
| +-- java/
| +-- Application.java
| +-- resources
| +-- application.properties
| +-- test/
| +-- java/
| +-- ApplicationTests.java
+-- target/
| +-- build output files
+-- mvnw
+-- mvnw.cmd
+-- pom.xml
- Both Java source code and the corresponding test files are contained in the
src/directory. - The
pom.xmlfile and the Maven wrappers are stored at the root of the project. - The
targetdirectory contains all the build output files.
Cargo uses the following conventions for the package layout to make it easy to dive into a new Cargo package:
project directory/
.
+-- Cargo.lock
+-- Cargo.toml
+-- src/
| +-- lib.rs
| +-- main.rs
+-- benches/
| +-- some-bench.rs
+-- examples/
| +-- some-example.rs
+-- tests/
+-- some-integration-test.rs
+-- target/
| +-- build output files
Cargo.tomlandCargo.lockare stored in the root of the package.src/lib.rsis the default library file, andsrc/main.rsis the default executable file (see target auto-discovery).- Benchmarks go in the
benchesdirectory, integration tests go in thetestsdirectory (see testing, benchmarking). - Examples go in the
examplesdirectory. - There is no separate crate for unit tests, unit tests live in the same file as the code (see testing).
Managing large projects
For very large projects in Rust, Cargo offers workspaces to organize the project. A workspace can help manage multiple related packages that are developed in tandem. Some projects use virtual manifests, especially when there is no primary package.