cargo run vs cargo build
A free lesson from Swipe Coding · Rust, level 2 · updated October 2026
By the Swipe team, founded by Colin · how we make lessons
cargo build compiles your project into a runnable binary, but it doesn't run that binary for you — it just leaves it sitting in the target/debug folder, waiting. cargo run does both steps in one: it compiles the project (recompiling only if something changed since last time) and then immediately runs the resulting binary.
cargo build ./target/debug/my_project # vs. doing both in one step: cargo run
There's also cargo check, which is faster than either: it asks the compiler to verify your code is correct without actually producing a runnable binary at all. It's handy while you're still writing code and just want quick feedback on whether it compiles.
Running ____ compiles a Rust project and then immediately runs the resulting binary, all in one step.
By default, both cargo build and cargo run produce a debug build: fast to compile, but not very optimized, and placed in target/debug. Adding the --release flag, as in cargo build --release, produces a much more optimized binary in target/release — it takes noticeably longer to compile, but the resulting program runs significantly faster, which is what you'd ship to real users.
cargo build --release ./target/release/my_project
Running cargo build without any flags produces an optimized binary in target/release.
Building & Running
10 questions · pass with 60% — just like in the app.
What does cargo build do?
cargo run compiles the project and then immediately runs the resulting binary.
Running ____ verifies your code compiles without producing a runnable binary at all.
Where does a default (non-release) cargo build place the compiled binary?
Passing --release to cargo build produces a more optimized binary that takes longer to compile.
Building with the ____ flag places an optimized binary in target/release instead of target/debug.
Which command is generally fastest, since it skips producing a runnable binary?
A debug build compiled with plain cargo build runs just as fast as a --release build.
What would you use during everyday development when you just want to try your code quickly?
An optimized binary meant for shipping to real users is typically built with cargo build ____.
Keep your streak going in Swipe Coding
Swipe through every level of Rust on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.
Get the Swipe apps →