gpt4 book ai didi

rust - Cargo 功能是否可以启用可选依赖项中的功能而不强制激活这些 crate ?

转载 作者:行者123 更新时间:2023-12-03 21:18:49 25 4
gpt4 key购买 nike

这是库箱的 Cargo.toml。它通过对板支持 crate board-a具有可选依赖关系来支持两个不同的嵌入式板。和 board-b ,并且通过运行 cargo build --features target-a 仅选择其中一个.

还有一个通用的第三方模块,可以选择使用const-fn特征。此选项在库 crate 中公开:

[dependencies]
common = {...}
board-a = {optional=true, ...}
board-b = {optional=true, ...}

[features]
const-fn = ["common/const-fn"]
target-a = ["board-a"]
target-b = ["board-b"]

到目前为止一切顺利,但如果 board-aboard-b crate 也有可选的 const-fn功能,我想向图书馆箱子的用户公开这些选项?我可以在不创建 target-a-const-fn 的情况下执行此操作吗?和 target-b-const-fn特征?我公开的可选功能越多,或者我们支持的板越多,这显然会变得非常困惑。

我不想制作 const-fn两个 crate 中的功能拉——只应使用选定的一个,否则会不必要地增加下载和编译时间。理想情况下,我想要与以下内容等效的东西,但据我所知,没有任何东西存在:
[features]
const-fn = ["common/const-fn", "board-a/const-fn" if target-a, "board-b/const-fn" if target-b]
target-a = ...

最佳答案

不,目前 Cargo 不支持此功能,尽管有 a tracking issue对于这个功能。

关于rust - Cargo 功能是否可以启用可选依赖项中的功能而不强制激活这些 crate ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52825268/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com