| name | workspace-shared-dependencies |
| description | Use when adding or modifying a dependency in a crate's `Cargo.toml` that is or may become shared by multiple workspace crates — keep its version defined in one place. |
Workspace-Level Shared Dependencies
Rule
When adding a dependency that another crate in the workspace already uses (or that you anticipate adding to another crate), declare it once in the root Cargo.toml's [workspace.dependencies] table. In each crate that uses it, write:
[dependencies]
serde = { workspace = true }
Don't duplicate version strings across crates. Don't keep a dependency crate-local once a second crate adopts it — promote it to the workspace.
For dependencies used in only one crate, keep them crate-local. Promote when a second crate starts using them.
Why
A workspace declaration is the single source of truth for a shared version. Without it, each crate pins its own, versions drift, cargo resolves duplicates, and compile times grow.
Examples
[workspace.dependencies]
serde = "1.0"
thiserror = "1.0"
[dependencies]
serde = { workspace = true, features = ["derive"] }
thiserror = { workspace = true }
[dependencies]
serde = "1.0"
[dependencies]
serde = "1.0.130"