In Cargo.toml
[workspace]
...
[workspace.dependencies]
slog = { version = "2.3", features = [
"max_level_trace",
"release_max_level_debug",
] }
slog-global = { version = "0.1", git = "https://github.com/tikv/slog-global.git", rev = "d592f88e4dbba5eb439998463054f1a44fbf17b9" }
If so, I can use the dependencies by
slog = { workspace = true }
slog-global = { workspace = true }
What if I introduced the dependecy again in some_components/Cargo.toml
?
[dependencies]
slog = { version = "2.3", features = [
"max_level_trace",
"release_max_level_debug",
] }
slog-global = { version = "0.1", git = "https://github.com/tikv/slog-global.git", rev = "d592f88e4dbba5eb439998463054f1a44fbf17b9" }
I actually found the behavior differs between nightly versions. In some nightly-2022 version, both imported slog and slog-global can work. However, when changed into nightly-2023 version, only using { workspace = true }
can work.
I know nightly versions are unstable. However, what is recommended to do? Is it strictly forbidden to introduce a dependency again by version or by git revision, if it is already introduced in workspace?
In the Cargo book, the author say we can inherit from workspace, however, it doesn’t say what will happen if we don’t.