Manifest: Conditionally enable library dependency features

I am working on a library, that optionally enables serde serialization.
This is my original dependency section

[dependencies]
chrono = { version = "0.4", features = ["serde"] }
flagset = { version = "0.4", features = ["serde"] }
nom = "7.1"
parse-display = "0.5"
serde = { version = "1.0", features = ["derive"], optional = true }

[features]
serde = ["dep:serde"]

Now this does not compile when not using serde, because chrono and flagset have the serde feature enabled.
Can anyone please refer me to a resource (or be said resource) explaining how to conditionally disable the serde feature in chrono and flagset?

Thanks a lot! Cheers

I think you want

[dependencies]
chrono = "0.4"
flagset = "0.4"
nom = "7.1"
parse-display = "0.5"
serde = { version = "1.0", features = ["derive"], optional = true }

[features]
serde = ["dep:serde", "chrono/serde", "flagset/serde"]
1 Like

Yes that did the trick for me. Any idea where this is documented? I haven't found it in the book.

Features - The Cargo Book has an explanation of this.

I have literally had that tab open and didn't see it. Darn I am blind ^^