Cheatsheet: Cargo (Rust)

Basic Commands

Create a new Rust project

cargo new <project_name>

Build a project

cargo build

Run a project

cargo run

Clean up build artifacts

cargo clean

Check project for errors without building

cargo check

Dependency Management

Add a new dependency

cargo add <dependency_name>

Update all dependencies

cargo update

List outdated dependencies

cargo outdated

Remove a dependency

cargo remove <dependency_name>

Testing & Documentation

Run all tests

cargo test

Run benchmarks

cargo bench

Generate documentation

cargo doc

Open generated documentation

cargo doc --open

Publishing & Versioning

Publish a crate to crates.io

cargo publish

Check a crate before publishing

cargo package

Bump version number

cargo version --bump <major|minor|patch>

Cargo Deny (Dependency Auditing)

Install cargo-deny

cargo install cargo-deny

Run cargo-deny check for security, licenses, and more

cargo deny check

Check for security advisories

cargo deny check advisories

Check for outdated dependencies

cargo deny check bans

Check for banned or incompatible licenses

cargo deny check licenses

Generate cargo-deny config file

cargo deny init