在我的项目中,我有两个功能:myfeatureA
和myfeatureB
.
我希望其中一个依赖于具有功能rt
和sync
的tokio
,而另一个依赖于仅具有功能sync
的tokio
.
我在Cargo.toml
分钟内try 了此配置:
[dependencies]
tokio = { version = "1.32", features = ["rt", "sync"], optional = true }
[features]
myfeatureA = ["dep:tokio"]
myfeatureB = ["dep:tokio/sync"]
$ cargo build --features=myfeatureB
error: failed to parse manifest at `[...]/myproject/Cargo.toml`
Caused by:
feature `myfeatureB` includes `dep:tokio/sync` with both `dep:` and `/`
To fix this, remove the `dep:` prefix.
因此,我删除了dep:
前缀(这是这个other question提供的解决方案,但它不起作用):
[features]
myfeatureA = ["dep:tokio"]
myfeatureB = ["tokio/sync"]
$ cargo build --features=myfeatureB
error: Package `myproject v0.1.0 ([...]/myproject)` does not have feature `tokio`. It has an optional dependency with that name, but that dependency uses the "dep:" syntax in the features table, so it does not have an implicit feature with that name.
我怎么才能让myfeatureB
依赖于只有sync
功能的tokio
呢?