2

Suppose I have a crate which depends on the glob crate only if #[cfg(feature = "glob")] is enabled. Also, this feature is disabled by default. How can I skip downloading and compiling of the glob crate by default?

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

[dependencies]
glob = "0.2"
...

And the source code:

# 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 
}
Ivan Velichko
  • 6,348
  • 6
  • 44
  • 90

1 Answers1

5

The glob dependency must be marked as optional:

[dependencies]
glob = { version = "0.2", optional = true }
mcarton
  • 27,633
  • 5
  • 85
  • 95