是否可以在禁用某个功能时启用另一个功能?

问题描述 投票:0回答:1

我有以下内容:

comfy-table = { version = "7.1.1", default-features = false }

[features]
wasm = []

我想要:

  • wasm
    功能启用时,应启用
    tty
    中的
    comfy-table
    功能;和
  • 如果
    wasm
    功能is启用了
    tty
    中的
    comfy-table
    功能,则应启用。

可以吗?

rust rust-cargo
1个回答
0
投票

不,但是有两个不错的选择。首先,您可以使用

target_arch
:

来检测 WebAssembly
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
comfy-table = { version = "7.1.1", features = ["tty"], default-features = false }

[target.'cfg(target_arch = "wasm32")'.dependencies]
comfy-table = { version = "7.1.1", default-features = false }

其次,你可以反转你的特征:

comfy-table = { version = "7.1.1", default-features = false }

[features]
tty = ["comfy-table/tty"]
© www.soinside.com 2019 - 2024. All rights reserved.