假设我有一个箱子,只有在glob
启用时才依赖#[cfg(feature = "glob")]
箱子。此外,默认情况下禁用此功能。如何在默认情况下跳过下载和编译glob
包?
# 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
}
答案 0 :(得分:5)
必须将glob
依赖项标记为可选:
[dependencies]
glob = { version = "0.2", optional = true }