Crate features

The second, very interesting, attribute use is to enable crate features. These features might encapsulate some functionality that some people using the crate don't need, therefore making it optional to compile. The Rust compiler will remove any unused code during the compilation, but not having some part of the code compile from the beginning will speed up the process.

You can define crate features in the Cargo.toml file by using the [features] section. You can specify some default features for the crate that will be built if nothing is specified:

[features]default = ["add"]add = []multiply = ["expensive_dependency"]

In this example, two features have been defined, the add feature and the multiply feature. The add feature does ...

Get Rust High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.