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.xml
file and the Maven wrappers are stored at the root of the project. - The
target
directory 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.toml
andCargo.lock
are stored in the root of the package.src/lib.rs
is the default library file, andsrc/main.rs
is the default executable file (see target auto-discovery).- Benchmarks go in the
benches
directory, integration tests go in thetests
directory (see testing, benchmarking). - Examples go in the
examples
directory. - 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.