Rust Cargo Basics
Package manager and build system for Rust
Project Commands
cargo new project_name # create new project
cargo init # initialize in existing directory
cargo build # compile project
cargo build --release # optimized build
cargo run # compile and run
Testing and Checking
cargo test # run tests
cargo check # check code without building
cargo doc # build documentation
cargo doc --open # build and open docs
Dependencies
cargo add serde # add dependency
cargo update # update dependencies
cargo tree # show dependency tree
Cargo.toml
# Project manifest file
[package]
name = "my_project"
version = "0.1.0"
edition = "2021"
[dependencies]
serde = "1.0" # add dependencies here
Workspaces
# Cargo.toml for workspace
[workspace]
members = [
"package1",
"package2",
]