rustrust-cargo

Is it possible to enable a specific feature when another feature is disabled?


I have the following:

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

[features]
wasm = []

I want:

Is it possible?


Solution

  • No, as features are additive, but there are two good alternatives. First, you could detect WebAssembly by using target_arch:

    [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 }
    

    (for completeness, note that you can try any(target_arch = "wasm32", target_arch = "wasm64") if the unstable 64-bit version of WebAssembly might be used)

    Second, you could invert your feature:

    comfy-table = { version = "7.1.1", default-features = false }
    
    [features]
    tty = ["comfy-table/tty"]