Cargo: workspace inheritance

Since 1.64.0, Cargo now supports workspace inheritance, so you can avoid duplicating similar field values between crates while working within a workspace. Workspace inheritance can include things like shared version numbers, repository URLs, or rust-version.

This also helps keep these values in sync between crates when updating them. This makes it easier to handle large workspaces.

Cargo workspace inheritance

File: [ROOT]/Cargo.toml

[workspace]
members = ["a", "b"]

[workspace.package]
version = "1.2.3"

[workspace.dependencies]
serde = "1.0.145"
anyhow = "1.0.65"

File: [ROOT]/a/Cargo.toml

[package]
name = "a"

# use the package version from [ROOT]/Cargo.toml
version.workspace = true

[dependencies]
# use `serde` version from [ROOT]/Cargo.toml
serde = { workspace = true }
# use `anyhow` version from [ROOT]/Cargo.toml
anyhow.workspace = true

For more details, see workspace.package, workspace.dependencies, and "inheriting a dependency from a workspace".

References

•Rust 🦀•RustCargo•