Features and dependencies cannot have the same name

I'm trying to give a library of mine optional serde support, but I'm confused about what to call the feature in my Cargo.toml. I've seen crates that have it called serde, and yet when I attempt this:

[features]
default = []
serde = ["serde"]

[dependencies]
serde = { version = "1.0", optional = true }

I get:

error: failed to parse manifest at `/home/colin/code/rust/kanji/Cargo.toml`

Caused by:
  Features and dependencies cannot have the same name: `serde`

Sure I could call it json or something, but serde isn't limited to JSON. Any idea of how to work around this? Thank you.

1 Like

When you have an optional dependency named serde, this automatically creates a feature named serde. You don't need to add anything to your [features] section.

3 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.