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
|       Class1.cs
|       SampleClassLibrary.csproj
  • Each project resides in a separate directory, with its own .csproj file.
  • At the root of the repository is a .sln file.

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/
|   +--
|   +--
+-- benches/
|   +--
+-- examples/
|   +--
+-- tests/
  • Cargo.toml and Cargo.lock are stored in the root of the package.
  • src/ is the default library file, and src/ is the default executable file (see target auto-discovery).
  • Benchmarks go in the benches directory, integration tests go in the tests 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.

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.