liveBook · Manning

Cargo feature

A Cargo feature is a named compile-time option that conditionally enables functionality or dependencies in a Rust package.

How 3 Manning books explain it

Write Powerful Rust Macros

A Cargo feature is a named compile-time configuration option that conditionally enables additive crate functionality or dependencies.

How it is used
Makes optional macro functionality selectable so consumers pull in only the library code they need.
How deep it goes
Demonstrates Cargo.toml declaration, cfg-gated imports and modules, consumer activation, failure testing, and default-feature trade-offs.
Examples
Uses an optional config_struct attribute macro, Serde derive macros, and Tokio’s macros feature and tokio-macros dependency.
What you can do after
Operate/configure optional macro APIs by declaring features, guarding code with cfg, and enabling requested features in dependencies.

Read how Write Powerful Rust Macros explains cargo feature →

Embedded Software with Rust

A Cargo feature is a named compile-time option that conditionally enables code or dependencies in a Rust package.

How it is used
Tailors embedded firmware to hardware variants and debugging or production configurations.
How deep it goes
Explains feature declarations, optional dependencies, conditional compilation, build commands, and dependency-feature inspection.
Examples
Uses STM32 HAL selection, semihosting and panic backends, and a single-core critical-section feature.
What you can do after
Apply it via Cargo to configure dependencies, select conditional code, and inspect enabled features.

Read how Embedded Software with Rust explains cargo feature →

Refactoring to Rust

A Cargo feature is a named configuration option that conditionally enables code paths, dependencies, or capabilities in a Rust crate.

How it is used
Enables optional Rust capabilities such as Serde's generated parsing and deserialization support.
How deep it goes
Explains conditional compilation and demonstrates dependency configuration, but does not develop general feature design.
Examples
Uses Cargo.toml's serde derive feature and a Rust struct deriving Debug and Deserialize.
What you can do after
Apply it via Cargo to enable dependency capabilities and deserialize JSON into a typed Rust struct.

Read how Refactoring to Rust explains cargo feature →

Related concepts

Questions about cargo feature

What is cargo feature?

A Cargo feature is a named compile-time option that conditionally enables functionality or dependencies in a Rust package.

Which Manning books explain cargo feature?

Write Powerful Rust Macros, Embedded Software with Rust and Refactoring to Rust.

What kinds of cargo feature are there?

Kinds of cargo feature include default feature and additive feature.

What is cargo feature part of?

Cargo feature is part of Cargo. Cargo is Rust’s package manager and build tool for managing projects and dependencies and for building, testing, and running Rust code.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.