Rust CLI Build, Run, Test, and Lint

Everyday Cargo workflows for checking, building, running, testing, formatting, linting, and cleaning Rust CLI projects.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Build and run

Fast iteration commands for local development.

Type-check without producing binaries

Validate code quickly without final artifacts.

bashANYcargocheck
bash
cargo check

Faster than a full build for many edit-compile cycles.

Build debug artifacts

Compile the package in the dev profile.

bashANYcargobuilddebug
bash
cargo build

Builds binaries and libraries for selected packages and targets.

Build optimized release artifacts

Compile with the release profile.

bashANYcargobuildrelease
bash
cargo build --release

Uses the `release` profile for optimized builds.

Build and run the default binary

Compile if needed and execute the program.

bashANYcargorun
bash
cargo run

Pass app arguments after `--` when needed.

Pass arguments to the binary

Separate Cargo flags from program flags with `--`.

bashANYcargorunargs
bash
cargo run -- --help

Arguments after `--` are forwarded to the compiled binary.

Run a specific binary target

Choose which binary to execute in multi-bin packages.

bashANYcargorunbin
bash
cargo run --bin admin-tool

Useful when the package exposes more than one executable.

Run an example target

Build and execute example code.

bashANYcargorunexample
bash
cargo run --example demo

Examples can be useful for smoke tests and documentation.

Tests and benches

Test execution, filtering, and output control.

Run the test suite

Build and run tests for the local package.

bashANYcargotest
bash
cargo test

The default workflow for unit tests, integration tests, and doctests.

Run a matching subset of tests

Filter tests by substring.

bashANYcargotestfilter
bash
cargo test parse_args

Great for tight feedback loops while debugging one area.

Show println output in tests

Pass test harness flags after `--`.

bashANYcargotestnocapture
bash
cargo test -- --nocapture

The flags after the separator go to the test harness, not Cargo.

Run tests serially

Force one test thread.

bashANYcargotestthreads
bash
cargo test -- --test-threads=1

Helps when tests share global state or external ports.

Run benchmarks

Execute benchmark targets if configured.

bashANYcargobench
bash
cargo bench

Benchmark support is available through Cargo benchmark targets.

Formatting, linting, cleaning

Keep code consistent and remove stale artifacts.

Format source code

Run rustfmt across the package.

bashANYcargofmtrustfmt
bash
cargo fmt

Requires the rustfmt component to be installed.

Check formatting in CI

Fail if files are not formatted.

bashANYcargofmtci
bash
cargo fmt -- --check

Common CI guard to enforce formatting.

Run Clippy lints

Analyze code for common mistakes and style issues.

bashANYcargoclippylint
bash
cargo clippy

Requires the Clippy component to be installed.

Treat warnings as errors

Fail the lint run on warnings.

bashANYcargoclippyci
bash
cargo clippy -- -D warnings

A stricter CI pattern for keeping lint debt low.

Remove build artifacts

Delete the `target` directory for the package.

bashANYcargoclean
bash
cargo clean

Useful when debugging stale builds or reclaiming disk space.

Profiles and target selection

Build specific targets or profiles.

Build one binary target

Compile a chosen binary only.

bashANYcargobuildbin
bash
cargo build --bin admin-tool

Targets can be selected individually in multi-target packages.

Build an example target

Compile only a chosen example.

bashANYcargobuildexample
bash
cargo build --example demo

Useful for verifying example code compiles.

Build tests without running them

Compile test artifacts only.

bashANYcargotestno-run
bash
cargo test --no-run

Good for CI stages or debugging compilation failures in tests.

Check all package targets

Type-check binaries, tests, examples, and benches.

bashANYcargochecktargets
bash
cargo check --all-targets

Broad validation helps catch code paths not built by default.

Recommended next

No recommendations yet.