在我的项目中,我有两个特点:myfeatureA
和myfeatureB
。
我希望其中一个依赖于tokio
,具有rt
和sync
特性,另一个依赖于tokio
,仅具有sync
特性。
我在Cargo.toml
中尝试了这个配置:
[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
仅依赖于tokio
的sync
特性?
2条答案
按热度按时间l3zydbqr1#
这在issue #10788中报告过,Rust 1.72.0修复了这个问题。现在您可以使用第二种方法(无
dep:
)。对于以前的版本,根本不使用
dep:
,即使是其他功能。不过,这会创建一个名为tokio
的功能。dwbf0jvd2#
完全不使用
dep:
(与文档建议的相反)可以工作:我猜
dep:
机制还没有完全实现。编辑:使用Rust 1.72,来自原始文章的第二个例子(参考):