Project Structure
While there are conventions around structuring a project in .NET, they are less strict compared to the Rust project structure conventions. When creating a two-project solution using Visual Studio 2022 (a class library and an xUnit test project), it will create the following structure:
.
| SampleClassLibrary.sln
+---SampleClassLibrary
| Class1.cs
| SampleClassLibrary.csproj
+---SampleTestProject
SampleTestProject.csproj
UnitTest1.cs
Usings.cs
- Each project resides in a separate directory, with its own
.csprojfile. - At the root of the repository is a
.slnfile.
Cargo uses the following conventions for the package layout to make it easy to dive into a new Cargo package:
.
+-- Cargo.lock
+-- Cargo.toml
+-- src/
| +-- lib.rs
| +-- main.rs
+-- benches/
| +-- some-bench.rs
+-- examples/
| +-- some-example.rs
+-- tests/
+-- some-integration-test.rs
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.
Managing dependency versions
When managing larger projects in .NET, it may be appropriate to manage the versions of dependencies centrally, using strategies such as Central Package Management. Cargo introduced workspace inheritance to manage dependencies centrally.