| name | rust-cargo-check |
| description | Prefer `cargo check` over `cargo build` when making Rust code changes. Use `cargo check` to quickly verify code compiles; only use `cargo build` when you need to run the executable. Use when this capability is needed. |
| metadata | {"author":"forrestthewoods"} |
Rust: Prefer cargo check Over cargo build
Key Principle
When working with Rust code, use cargo check to verify code compiles. Only use cargo build when you actually need to run the resulting executable.
Why cargo check is Preferred
| Command | What it does | Speed |
|---|
cargo check | Type-checks and validates code compiles | Fast |
cargo build | Full compilation + produces executable | Slow |
cargo check skips the code generation and linking phases, making it significantly faster than cargo build - often 2-5x faster or more.
When to Use Each Command
Use cargo check when:
- Making code changes and verifying they compile
- Iterating on fixes for compiler errors
- Refactoring code
- Adding new functions, structs, or modules
- Fixing type errors
- Any time you just need to know "does this compile?"
cargo check
cargo check --all-features
cargo check --release
Use cargo build when:
- You need to run the executable afterward
- You're about to execute
cargo run
- You need to test the actual binary output
- You're preparing a release artifact
cargo build --release && ./target/release/myapp
cargo run --release -- <args>
Workflow Example
Fixing a Compile Error
cargo check
cargo check
cargo test
cargo build --release
Iterating on Code Changes
cargo check
cargo check
cargo check
cargo run --release -- <args>
Common Patterns
After Editing Rust Files
cargo check
cargo build
Before Running Tests
cargo test
When You Need to Run the Binary
cargo run --release -- build -m //mode:win_dev -t //target:name
cargo build --release
./target/release/anubis build -m //mode:win_dev -t //target:name
Summary
| Situation | Command |
|---|
| Check if code compiles | cargo check |
| Run tests | cargo test |
| Run the program | cargo run |
| Build for distribution | cargo build --release |
| Iterate on fixes | cargo check (repeatedly) |
Default to cargo check - it's your fast feedback loop for Rust development.
Converted and distributed by TomeVault — claim your Tome and manage your conversions.