2

假设我有一个仅在启用glob时才依赖于该板条箱的板条箱。#[cfg(feature = "glob")]此外,默认情况下禁用此功能。如何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 
}
4

1 回答 1

5

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

[dependencies]
glob = { version = "0.2", optional = true }
于 2016-08-29T16:44:19.377 回答