[dependencies]
serde = "1.0"The default registry used by Cargo is crates.io.
Dependency declarations, feature flags, workspace commands, and reusable patterns for larger Rust CLI projects.
Define registry, git, path, and dev dependencies.
[dependencies]
serde = "1.0"The default registry used by Cargo is crates.io.
[dependencies]
mycrate = { git = "https://github.com/org/mycrate.git", branch = "main" }Git dependencies are useful for unreleased fixes or internal code.
[dependencies]
common = { path = "../common" }Path dependencies are common in workspaces and local development.
Keep test-only crates out of the normal build graph.
[dev-dependencies]
assert_cmd = "2"
predicates = "3"Development dependencies are compiled for tests, examples, and benches.
[build-dependencies]
cc = "1"Build dependencies are only available to the build script.
Control optional code and dependency behavior.
[features]
default = ["color"]
color = []
json = ["dep:serde_json"]Cargo features enable or disable optional functionality.
cargo build --features json,colorUse a comma-separated feature list for the local package.
cargo test --no-default-featuresUseful to verify optional code paths compile independently.
cargo check --all-featuresHelpful in CI for validating the full feature matrix.
Group crates into one workspace and operate across members.
[workspace]
members = ["crates/*", "xtask"]
resolver = "2"Workspaces let multiple packages share one lockfile and target directory.
cargo build --workspaceA common command at the monorepo root.
cargo test --workspaceHelps enforce repository-wide quality gates.
cargo check -p xtaskUse `-p` or `--package` to focus on one workspace member.
cargo test --workspace --exclude xtaskUseful when a member needs a different environment.
Patterns often used in Rust command-line tools.
use clap::Parser;
#[derive(Parser, Debug)]
struct Args {
#[arg(long)]
verbose: bool,
#[arg(long, default_value = ".")]
path: String,
}The `clap` ecosystem is a common choice for Rust CLI argument parsing.
fn main() -> anyhow::Result<()> {
println!("hello");
Ok(())
}Returning `Result` from `main` is a clean pattern for CLI apps.
RUST_LOG=info cargo runMany Rust apps use environment-controlled logging during development.