Cargo Workflow · 14 min · free lesson

Check, Build, Run

Choose the cheapest command that proves the next fact.

Core idea

cargo check proves type correctness without final code generation, build creates artifacts, and run executes a binary after building it.

The edit, cargo check, cargo test, cargo run loop branches to a release build for shipping.
Ask Cargo for the evidence needed at each stage of development.

Understand it

cargo check proves type correctness without final code generation, build creates artifacts, and run executes a binary after building it. Fast feedback comes from asking only for the evidence you need.

The fastest useful command depends on the question you are asking. After an edit, cargo check verifies parsing, types, borrowing, and many other compiler rules without producing a final executable. cargo test compiles the test harness and runs tests. cargo run builds a binary if needed and executes it. cargo build produces an artifact without executing it. cargo run reuses what cargo build produced, while cargo check keeps its own output, and each command provides different evidence.

A productive loop is edit, check, test the changed behavior, then run the whole program when interaction matters. A successful cargo check does not prove a function returns the right answer; a passing unit test does not prove the CLI arguments are wired correctly. cargo build --release uses the release profile and is appropriate when validating a shippable artifact or measuring optimized performance. It is usually slower than a quick debug check during a small edit.

Try introducing a type mismatch and observe which command catches it first. Fix that, then introduce a logic bug that compiles but fails an assertion. Finally run the application with a representative input. Record what each stage established and what it left untested. This distinction prevents “it compiled” from becoming an overconfident claim. Keep the loop short while developing, and use broader checks at meaningful checkpoints rather than waiting until the end of the project.

For a library-only package, cargo run has no default binary to execute; choose an example or add a binary target. In a workspace, a command may need -p package_name to identify which member you mean. These small command choices keep feedback focused.

Read the code

// Fast type feedback:
// cargo check
// Produce an executable:
// cargo build
// Build and execute:
// cargo run

Three commands, three levels of evidence: types, an artifact, then a run.

Practice starter

fn double(value: i32) -> i32 {
    value + 2
}

fn main() {
    println!("{}", double(4));
}

Practise this code in Playground ↗

Try it

Say which of cargo check, cargo build, and cargo run first reveals that double(4) gives 6, not 8. Then break the return type and ask the same question.

What success looks like: You can name the fact each command proved and the fact it left untested.

Check your understanding

Which command skips final code generation?

Reveal the answer
  1. cargo check
  2. cargo build
  3. cargo run

cargo check stops after analysis, so it reports type and borrow errors without producing an executable.

Go deeper

Common misconception: “A passing cargo check means the program does the right thing.”

cargo check proves type correctness without final code generation, so logic bugs survive it. cargo run executes the binary and shows its behaviour.

  1. Ask for types: cargo check parses, type checks, and borrow checks the crate, with no executable at the end.
  2. Ask for a binary: cargo build also runs code generation and leaves an executable under target/debug, without starting it.
  3. Ask for behaviour: cargo run builds if anything changed, then executes that binary, so it is the only one of the three that shows output.

Transfer challenge: Add a test for double and put cargo test into the list. Say where it belongs between cargo check and cargo run, and what a pass proves that cargo check cannot.

Connections

  • Package Layout: Map Cargo targets to predictable source paths
  • Dependency Kinds: Separate runtime, build, and test-only tools
Learn this lesson with AI

Paste this into Claude, Codex, Cursor or another agent connected to Crabrix Academy. It contains only this lesson’s public details.

I'm learning Rust with Crabrix Academy. Teach me this lesson with the Crabrix Academy tools.
Lesson: Check, Build, Run (courseId "projects", lessonId "cargo-command-cycle")
Link: https://crabrix.com/learn/projects/cargo-command-cycle/
Goal: cargo check proves type correctness without final code generation, build creates artifacts, and run executes a binary after building it.
Practice: open the starter in the Crabrix Playground (https://crabrix.com/playground/?lesson=projects/cargo-command-cycle) and I will write the code there.
Explain it step by step for my level, let me write the code myself, give hints before any solution, and do not mark anything as passed: only Crabrix checks do that.

In Claude Code, Codex or Cursor, paste it into a chat with Crabrix Academy connected. On a phone, the Claude and ChatGPT apps open the same links.