In Rust Cargo, how can I include optional features of dependencies, depending on the inclusion of another dependency?
Specifically, I would like to offer a "serde" feature, which enables serde support. What I can do is [1]
[dependencies]
serde = { version = "1.0", optional = true }
Rust exports this dependency as a feature automatically (as I understand it). However, I use other dependencies, which offer a "serde" feature, too:
[dependencies]
otherpackage = { version = "1.0", features = ["serde"] }
serde = { version = "1.0", optional = true }
Now, the serde feature of "otherpackage" should only be included if the "serde" feature is activated for this package. But cargo does not let me do
[features]
serde = [ "serde", "otherpackage/serde" ]
[dependencies]
otherpackage = { version = "1.0" }
serde = { version = "1.0", optional = true }
I understand this is due to a name clash between the "serde" feature and the "serde" dependency, which I think is also exported as a feature. So, in essence there are now two "serde" features, which obviously does not work.
How can I solve this with still offering a "serde" feature and without renaming the "serde" package? Ideally, I would just like to disable the automatic exporting of the serde dependency as a feature or be able to specify a feature dependency of the "serde" package.