Organize a Rust project into crates, modules and workspaces
8 steps · about 2 h 15 min · Intermediate
- Tell packages, crates and modules apart (tutorial, The Rust Book, 10 min)
Sets out the module system vocabulary that every later step depends on.
- Group code into modules and control privacy (tutorial, The Rust Book, 20 min)
Shows the module tree, pub and how privacy works between parent and child modules.
- Move modules into their own files (tutorial, The Rust Book, 10 min)
Maps the module tree onto files and folders as a crate grows.
- Experiment with pub(crate) and pub(super) (interactive, Rust by Example, 15 min)
Editable examples of every visibility level you can change and run.
- Split the project into a workspace (tutorial, The Rust Book, 20 min)
Builds a workspace with a binary and library crates sharing one lockfile and target directory.
- Share dependencies and settings across members (reference, The Cargo Book, 20 min)
Covers workspace.dependencies, inherited package fields and default members.
- Gate optional code behind Cargo features (reference, The Cargo Book, 25 min)
Explains additive features, optional dependencies and how feature unification works.
- Check the exact visibility rules (reference, The Rust Reference, 15 min)
States precisely what pub(in path), pub(crate) and re-exports allow.