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
Type-check without producing binaries
cargo check

# Validate code quickly without final artifacts.

Build debug artifacts
cargo build

# Compile the package in the dev profile.

Build optimized release artifacts
cargo build --release

# Compile with the release profile.

Build and run the default binary
cargo run

# Compile if needed and execute the program.

Pass arguments to the binary
cargo run -- --help

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

Run a specific binary target
cargo run --bin admin-tool

# Choose which binary to execute in multi-bin packages.

Run an example target
cargo run --example demo

# Build and execute example code.

## Tests and benches
Run the test suite
cargo test

# Build and run tests for the local package.

Run a matching subset of tests
cargo test parse_args

# Filter tests by substring.

Show println output in tests
cargo test -- --nocapture

# Pass test harness flags after `--`.

Run tests serially
cargo test -- --test-threads=1

# Force one test thread.

Run benchmarks
cargo bench

# Execute benchmark targets if configured.

## Formatting, linting, cleaning
Format source code
cargo fmt

# Run rustfmt across the package.

Check formatting in CI
cargo fmt -- --check

# Fail if files are not formatted.

Run Clippy lints
cargo clippy

# Analyze code for common mistakes and style issues.

Treat warnings as errors
cargo clippy -- -D warnings

# Fail the lint run on warnings.

Remove build artifacts
cargo clean

# Delete the `target` directory for the package.

## Profiles and target selection
Build one binary target
cargo build --bin admin-tool

# Compile a chosen binary only.

Build an example target
cargo build --example demo

# Compile only a chosen example.

Build tests without running them
cargo test --no-run

# Compile test artifacts only.

Check all package targets
cargo check --all-targets

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

Recommended next

No recommendations yet.