Cargo Workflow · 18 min · free with an account

Feature Design

Lesson preview · about 30%

Make optional capability additive and explicit.

Core idea

Cargo features are unified across a dependency graph, so disabling one consumer's feature may not disable it globally.

Start with the idea

Cargo features are unified across a dependency graph, so disabling one consumer's feature may not disable it globally. Prefer additive capabilities and avoid features that make the same API mean incompatible things.

A feature is a named, additive capability a crate can enable at compile time. #[cfg(feature = "color")] includes code only when that feature is active; another branch can provide behavior without it. A feature is not a runtime switch, so a binary cannot toggle it after compilation. The public API exposed under different feature sets should be understandable and tested in each supported configuration.

Cargo unifies feature requests for the same package in a dependency graph.

Keep learning, for free

The rest of this lesson is waiting for you.

Create a free account to read the complete explanation, see the infographic, explore the code, and try the exercises. All 742 lessons and algorithm steps are included.

No payment details. Your account opens the complete Academy.

← All lessons in Cargo & Real Projects