cargo-manifest

Rust Optional dependencies

A feature can activate a dependency only when the extra capability is needed. The dep: prefix explicitly associates a feature with an optional dependency and suppresses its implicit same-name feature. Example format: toml; run from a disposable copy of v15/fixtures/projects/feature-app. Expected result (not executed): With default features, output is Welcome; without defaults, Plain. Why: Only the enabled branch needs the label library at compilation time. Common mistake: Importing label unconditionally while allowing the dependency to be disabled.

Formal Syntax & Structure

rust syntaxrust
optional = true; dep:NAME

Working Example

Example Snippetrust
[dependencies]label = { path = "label", optional = true }[features]default = ["friendly"]friendly = ["dep:label"]
Rust Reference