Cargo Rust package manager
Light · Postcard
102 × 152 mm · PDF
Dark · Postcard
102 × 152 mm · PDF
Ink saver · Postcard
102 × 152 mm · PDF
Light · A4 landscape
297 × 210 mm · PDF
Dark · A4 landscape
297 × 210 mm · PDF
Ink saver · A4 landscape
297 × 210 mm · PDF
Light · A3 landscape
420 × 297 mm · PDF
Dark · A3 landscape
420 × 297 mm · PDF
Ink saver · A3 landscape
420 × 297 mm · PDF
Start here
cargo new <name>
cargo runcargo checkcargo testcargo add <crate>
cargo build --release
cargo fmtcargo clippyConcepts
Projects
cargo new <name>
cargo initcargo runcargo run --bin <name>
cargo run --example <name>
cargo cleancargo doc --open
cargo install <crate>
cargo install --path .
cargo uninstall <crate>
Build & check
cargo buildcargo build --release
cargo checkcargo check --all-targets
cargo build --target <triple>
cargo build --timings
cargo fetchcargo fixTest & lint
cargo testcargo test <filter>
cargo test -- --nocapture
cargo test --lib
cargo test --doc
cargo test --test <name>
cargo test --no-fail-fast
cargo test -- --exact <path>
cargo test -- --test-threads=1
cargo test --no-run
cargo benchcargo fmtcargo fmt --check
cargo clippycargo clippy -- -D warnings
Dependencies
cargo add <crate>
cargo add <crate>@<ver>
cargo add --dev <crate>
cargo add <crate> -F <feat>
cargo add --dry-run <crate>
cargo remove <crate>
cargo updatecargo update <crate>
cargo update <crate> --precise <ver>
cargo treecargo tree -i <crate>
cargo tree -dcargo tree -e features -i <crate>
cargo search <term>
cargo metadata --format-version 1
Features
cargo build --features <list>
cargo build --no-default-features
cargo build --all-features
cargo build -F <pkg>/<feat>
[features]default = ["json"]json = ["dep:serde_json"]fast = [][dependencies]serde_json = { version = "1", optional = true }
Profiles
| Setting | dev | release |
|---|---|---|
opt-level |
0 |
3 |
debug |
true |
false |
debug-assertions |
true |
false |
overflow-checks |
true |
false |
incremental |
true |
false |
cargo build --profile <name>
[profile.release]lto = truecodegen-units = 1panic = "abort"strip = "symbols"[profile.release-debug]inherits = "release"debug = true
Workspaces
cargo build --workspace
cargo test -p <pkg>
cargo build -p <pkg>
cargo test --workspace --exclude <pkg>
cargo run -p <pkg>
[workspace]members = ["crates/*"]resolver = "3"[workspace.dependencies]serde = "1"
[dependencies]serde = { workspace = true }
Publishing
cargo logincargo package --list
cargo publish --dry-run
cargo publishcargo publish -p <pkg>
cargo yank <version>
cargo owner --add <user>
Recipes
cargo new hello && cd hellocargo add clap -F derivecargo run
cargo fmt --checkcargo clippy --all-targets -- -D warningscargo test --workspace --locked
cargo tree -dcargo tree -i <crate>@<ver>
cargo testcargo publish --dry-rungit tag v<ver> && cargo publish
Help
cargo help <command>
cargo <command> -h
cargo --list



