gpt4 book ai didi

dependencies - 如果禁用相关功能,如何跳过依赖项

转载 作者:行者123 更新时间:2023-11-29 08:03:59 24 4
gpt4 key购买 nike

假设我有一个 crate ,它仅在 #[cfg(feature = "glob")] 启用时才依赖于 glob crate 。此外,默认情况下禁用此功能。默认情况下,如何跳过 glob crate 的下载和编译?

# Cargo.toml
...
[features]
default = []

[dependencies]
glob = "0.2"
...

和源代码:

# lib.rs
.. several uses

#[cfg(feature = "glob")]
extern crate glob;

... a lot of code that doesn't use glob crate.

#[cfg(feature = "glob")]
impl Foo for Bar {
// only this code uses glob crate
}

最佳答案

glob 依赖项必须标记为可选:

[dependencies]
glob = { version = "0.2", optional = true }

关于dependencies - 如果禁用相关功能,如何跳过依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39210887/

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