在我的项目中,我有两个功能:myfeatureAmyfeatureB.

我希望其中一个依赖于具有功能rtsynctokio,而另一个依赖于仅具有功能synctokio.

我在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呢?

推荐答案

这是在issue #10788中报告的,已在铁 rust 1.72.0中修复.现在您可以使用第二种方法(编号dep:).

对于以前的版本,根本不要使用dep:,即使是其他功能.不过,这会创建一个名为tokio的功能.

Rust相关问答推荐

Rust,polars CSV:有没有一种方法可以从impll BufRead(或任何字节迭代器)中读取CSV?

PyReadonlyArray2到Vec T<>

如何使用syn插入 comments ?

告诉Rust编译器返回值不包含构造函数中提供的引用

S在Cargo.toml中添加工作空间开发依赖关系的正确方法是什么?

在rust sqlx中使用ilike和push bind

我可以在不收集或克隆的情况下,将一个带有Item=(key,val)的迭代器拆分成单独的key iter和val iter吗?

我是否可以在Ruust中修改 struct 实例上的字符串,以使其在修改后具有相同的字符串生存期?

异步函数返回的future 生存期

允许 rust 迹 struct 条目具有多种类型

关于使用平面图功能的borrow 判断器的问题

如何在Rust中缩短数组

应为关联类型,找到类型参数

RUST 中的读写器锁定模式

Rust 中的复合 `HashSet` 操作或如何在 Rust 中获得 `HashSet` 的显式差异/并集

如何使用tracing-subscriberRust crate 构建多编写者、全局过滤订阅者

rust 中不同类型的工厂函数

从 Cranelift 发出 ASM

Cargo:如何将整个目录或文件包含在功能标志中?

为什么一个整型变量赋值给另一个变量后仍然可以使用?