Rust’s tooling is its quiet superpower. cargo handles dep management, build, test, doc, publish — out of the box. Add a few lints + nextest and you have a CI/CD-friendly setup that catches more bugs than most languages dream of. This post is the working setup.
Cargo basics for 2026
# Cargo.toml
[package]
name = "my-app"
version = "0.1.0"
edition = "2024"
rust-version = "1.85"
[dependencies]
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
anyhow = "1"
thiserror = "2"
[dev-dependencies]
pretty_assertions = "1"
[lints.rust]
unused_must_use = "warn"
unused_qualifications = "warn"
[lints.clippy]
all = "warn"
pedantic = "warn"
nursery = "warn"
# allow some noisy ones
module_name_repetitions = "allow"
must_use_candidate = "allow"
[lints] (Cargo 1.74+) sets per-crate lint levels in Cargo.toml — no more boilerplate #![deny(...)] in lib.rs.
Workspaces
For multi-crate projects:
# Cargo.toml (workspace root)
[workspace]
members = ["app", "core", "api", "cli"]
resolver = "2"
[workspace.dependencies]
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
anyhow = "1"
[workspace.lints.clippy]
all = "warn"
Then in each crate:
[package]
name = "core"
[dependencies]
tokio.workspace = true
anyhow.workspace = true
[lints]
workspace = true
Single source of truth for dep versions. Lint config inherited.
Essential commands
cargo check # fast type-check
cargo build --release # optimized build
cargo test # tests
cargo clippy --all-targets -- -D warnings # lint, fail on warnings
cargo fmt --check # format check (CI)
cargo doc --open # docs
cargo run --bin my-app
Faster tests with nextest
cargo install cargo-nextest
cargo nextest run # 2–3× faster than cargo test
cargo nextest run --profile ci # parallel, retries, structured output
Replaces cargo test for CI. Failures are clearer; concurrency is sane; retries supported.
Watch mode
cargo install cargo-watch
cargo watch -x check -x test # rerun on file changes
Tight feedback loop while developing.
Format on save
cargo fmt
rustfmt.toml:
edition = "2024"
max_width = 100
imports_granularity = "Crate"
group_imports = "StdExternalCrate"
Editor-on-save format. No bikeshedding about style.
CI in 50 lines
# .github/workflows/ci.yml
name: ci
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with: { components: rustfmt, clippy }
- uses: Swatinem/rust-cache@v2
- run: cargo fmt --check
- run: cargo clippy --all-targets --all-features -- -D warnings
- uses: taiki-e/install-action@nextest
- run: cargo nextest run --profile ci
audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: rustsec/audit-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
rust-cache caches compilation across runs. audit-check flags known-vulnerable deps.
Useful cargo plugins
| What | |
|---|---|
| cargo-nextest | Better test runner |
| cargo-watch | Rerun on changes |
| cargo-audit | Security audit |
| cargo-deny | License + dep policy |
| cargo-machete | Find unused deps |
| cargo-llvm-cov | Code coverage |
| cargo-insta | Snapshot testing |
| cargo-flamegraph | Profile (Linux) |
| bacon | Better cargo-watch |
Build profiles
[profile.release]
lto = "thin"
codegen-units = 1
strip = true
opt-level = 3
[profile.dev]
opt-level = 0
debug = true
[profile.dev.package."*"]
opt-level = 2 # deps in optimized mode even in dev — faster runs
profile.dev.package."*" is underused: keeps your code in fast-compile dev mode but optimizes deps. Tests run dramatically faster.
What I’d ship today
For a new Rust crate / workspace:
- Workspaces with shared lints.
- Clippy + pedantic as warnings, denied in CI.
- rustfmt on save + check in CI.
- cargo-nextest for tests.
- cargo-watch / bacon in dev.
- cargo-audit in CI.
- rust-cache to keep CI under 2 minutes.
Boring. Effective.
Read this next
If you want a Rust workspace template wired up, it’s at rajpoot.dev .
Building something AI-, backend-, or data-heavy and want a second pair of eyes? I do consulting and freelance work — see my projects and ways to reach me at rajpoot.dev .