货物条件依赖功能

rit*_*e46 5 rust rust-cargo

我想包含依赖项的功能,这些功能取决于我的库中功能的激活。如果我使用 feature 进行编译"serde",我想ndarray使用"serde"support 进行安装。并且默认应该是默认ndarray安装。

我想要这样的东西Cargo.toml


[features]
include-serde = ["ndarray-with-serde"]

[dependencies]
ndarray = { version = "0.x" }
ndarray-with-serde = { version = "0.x", features=["serde"] }
Run Code Online (Sandbox Code Playgroud)

目前这可能吗?

rit*_*e46 3

您可以在 后添加 crate 的功能/

[features]
myfeature = ["library_foo/bar", "libary_foo/ham"]

[dependencies]
library_foo = { version = "0.x" }
Run Code Online (Sandbox Code Playgroud)

上面的代码片段安装功能"bar"以及"ham"激活"library_foo"时间"myfeature"