Dependencies; optional tokio imply tokio-util

I have a crate in which I want to have optional support for tokio, but when the tokio feature is enabled, I want it to imply tokio-util as well. I want to express something along the line of:

tokio = ["tokio", "tokio-util"]

tokio-util = { version = "0.6", optional = true }

version = "1"
features = ["net"]
optional = true

This doesn't work because:

Caused by:
  optional dependency `tokio` is not included in any feature
  Make sure that `dep:tokio` is included in one of features in the [features] table.

I can easily work around this by renaming tokio under [features] to something else. My questions are:

  • Much like crates that support serde have a serde feature, it really would be nice to have a tokio feature, though I understand if this can't be done. Is there a way to express the implied dependency on tokio-util when the feature tokio is used?
  • If the answer is "no" to the previous question, then I wonder if there's some de-facto standard convention to naming features which are used in this manner?

You can rename the dependency instead and have the feature be the thing named Tokio.

1 Like

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.