场景如下:我的 crate 依赖于num-bigint
,并且可选依赖于rand
:
[dependencies]
num-bigint = { version = "0.2" }
rand = { version = "0.7", optional = true }
当rand
我的箱子被禁用时,一切都很好。
当rand
在我的箱子上启用时,我希望也启用该rand
功能num-bigint
。我怎样才能做到这一点?
这是我尝试过的:
[target.'cfg(feature = "rand")'.dependencies]
num-bigint = { version = "0.2", features = ["rand"] }
这有效,但我收到此警告:
warning: Found `feature = ...` in `target.'cfg(...)'.dependencies`. This key is not supported for selecting dependencies and will not work as expected. Use the [features] section instead: https://doc.rust-lang.org/cargo/reference/features.html
我应该忽略警告,还是有更好的方法?我检查了那个网页,但我找不到任何有用的东西。