Rust: cargo and rustup
Projects and dependencies, building and testing, lints and formatting, toolchains and cross-compilation.
Projects
New binary / library project
cargo new <project> && cargo new --lib <project>-core
Add a dependency (with features)
cargo add <crate> --features full
Update dependencies within semver
cargo updateBuild and run
Fast check without building
cargo checkRun (with arguments)
cargo run -- --helpRelease build
cargo build --releaseInstall a CLI from crates.io
cargo install <crate>
Tests and quality
All tests
cargo testTests matching a name, with println output
cargo test <test_method> -- --nocapture
Lints, failing on warnings
cargo clippy --all-targets -- -D warningsFormat
cargo fmtCheck dependencies for known vulnerabilitiesadvanced
cargo install cargo-audit && cargo auditWho depends on a crateadvanced
cargo tree -i <crate>
rustup
Update the toolchain
rustup updatePin a toolchain for the projectadvanced
rustup override set 1.85.0Add a cross-compilation targetadvanced
rustup target add aarch64-unknown-linux-gnu && cargo build --release --target aarch64-unknown-linux-gnu