Rust CLI Troubleshooting: Manifest, Packages, and Workspaces/Declare optional dependencies with features

Avoid feature-resolution confusion.

Section: Manifest repair snippets

Declare optional dependencies with features

toml
toml
[dependencies]
clap = { version = "4", features = ["derive"] }
serde_json = { version = "1", optional = true }

[features]
default = []
json = ["dep:serde_json"]
Explanation

Feature wiring mistakes in `Cargo.toml` are a common source of build confusion in CLI apps.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Manifest repair snippets
Define an explicit binary target
Name and path a binary target clearly.
OpenIn sheettomlsame section
Define workspace members explicitly
Basic workspace root snippet.
OpenIn sheettomlsame section
Locate the active Cargo.toml
Show which manifest Cargo is using.
OpenIn sheetbash2 tag match
Locate the workspace root
Show the workspace root manifest path.
OpenIn sheetbash2 tag match
Inspect resolved metadata
Print package and dependency metadata as JSON.
OpenIn sheetbash1 tag match
Build one workspace member
Select a specific package inside a workspace.
OpenIn sheetbash1 tag match