| name | rust-dependencies |
| description | Rust dependency management principles for this workspace. Use whenever adding, updating, removing, or reviewing dependencies in any Cargo.toml — including deciding which version to use, where to declare a dep, or auditing for duplicates.
|
Rules
-
Workspace-level declarations only. All dependencies must be declared in [workspace.dependencies] in the root Cargo.toml. Never add a versioned dependency directly to a crate's [dependencies].
-
Crate Cargo.toml references workspace. In each crate, reference workspace deps with:
some-crate = { workspace = true }
some-crate = { workspace = true, features = ["extra"] }
-
Always use the latest version. When adding a new dependency, look up and use the latest stable version on crates.io. Do not copy an old version from existing entries.
-
Check before adding. Before declaring a new dep in [workspace.dependencies], grep the root Cargo.toml to confirm it isn't already there (possibly under a different feature set).
-
No duplicate transitive deps. Avoid adding a crate that is already pulled in transitively. Run cargo tree -d to surface duplicates. Prefer cargo machete --with-metadata to detect unused deps.
Workflow
When adding a dependency:
- Check root
Cargo.toml [workspace.dependencies] — is it already declared?
- If not, add it there with the latest version.
- In the target crate's
Cargo.toml, add { workspace = true }.
- After changes, run
make lint to catch any issues.
When removing a dependency:
- Remove the
{ workspace = true } reference from the crate.
- If no other crate uses it, remove the entry from
[workspace.dependencies] too.
- Run
cargo machete --with-metadata to confirm nothing is left unused.