DevTools

Cargo CLI

Rust Cargo commands for package management and building.

28 commands
Windows MacOS Linux
#rust #package-manager

Project Management

Create a new project in a directory
cargo init my-project
Create a new binary project
cargo new my-project
Create a new library project
cargo new --lib my-lib
Remove the target directory
cargo clean

Build & Run

Build the project in debug mode
cargo build
Build with optimizations
cargo build --release
Build and run the project
cargo run
Build and run in release mode
cargo run --release
Run a specific example
cargo run --example demo
Check code without producing binary
cargo check

Testing

Run all tests
cargo test
Run tests matching a name
cargo test my_test
Run tests showing stdout
cargo test -- --nocapture
Run benchmarks
cargo bench
Run documentation tests
cargo test --doc

Dependencies

Add a dependency
cargo add serde
Add dependency with features
cargo add tokio --features full
Remove a dependency
cargo remove serde
Update all dependencies
cargo update
Display dependency tree
cargo tree

Publishing

Save API token for crates.io
cargo login
Package and publish to crates.io
cargo publish
Verify package before publishing
cargo publish --dry-run
Create a distributable package
cargo package
Generate and open documentation
cargo doc --open

Quick Commands

Compile the current project
cargo build
Build and execute the project binary
cargo run
Run the project test suite
cargo test