我正在 Cargo 中编写一个库。如果这个库依赖于另一个库,例如
libc
,它公开了一个功能(在本例中为 use_std
),我如何使我公开的功能在我的依赖项中启用或禁用该功能?
查看cargo 文档,似乎没有指定官方方法来执行此操作。
来自 您链接到的文档:
# Features can be used to reexport features of other packages. The `session` # feature of package `awesome` will ensure that the `session` feature of the # package `cookie` is also enabled. session = ["cookie/session"]
这样就够了吗?
为了补充其他答案,我发现当我从不同的路径包含我自己的项目时,当我使用标志进行编译时,我还必须在我的依赖项中包含
default-features = false
。像这样:
[package]
name = "A"
version = "0.1.0"
edition.workspace = true
[features]
stage = ["B/stage"]
[dependencies]
eyre.workspace = true
tokio.workspace = true
[dependencies.B]
path = ".."
default-features = false # Without this, I couldn't pass the `stage` feature down to my dependency