Tôi là Duyệt

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
Cargo workspace inheritance

File: [ROOT]/Cargo.toml

members = ["a", "b"]

version = "1.2.3"

serde = "1.0.145"
anyhow = "1.0.65"

File: [ROOT]/a/Cargo.toml

name = "a"

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

# 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”.