Skip to content

Build, run and test

Rust is a compiled language: before running a program, the compiler (rustc, through Cargo) checks all the code and turns it into an executable. If it finds an error, nothing runs: it tells you what and where, and almost always how to fix it.

Button Shortcut What it does Equivalent to
Build Ctrl/⌘+Shift+B Builds without running cargo build
Check Checks with Clippy: errors and style suggestions cargo clippy
Test Runs the tests (#[test]) cargo test
Debug F5 Builds and runs with the debugger
Run Ctrl/⌘+F5 Builds and runs, without breakpoints cargo run
Stop Shift+F5 Stops the program or the build

They’re all in the Project menu too. Open files are saved before building.

When building, errors and warnings go to the Error list in the bottom panel (the red and yellow counters on the tab). Click one to go to its line. In the editor they’re underlined, and many have a quick action (Ctrl/⌘+.) that fixes them.

Rust’s messages are long but useful. For example:

error[E0384]: cannot assign twice to immutable variable `total`
--> src/main.rs:3:5
|
2 | let total = 0;
| ----- first assignment to `total`
3 | total += 5;
| ^^^^^^^^^^ cannot assign twice to immutable variable
|
help: consider making this binding mutable
|
2 | let mut total = 0;
| +++

The help: part shows how to fix it: add mut (the +++ mark what to add). The code (E0384) can be looked up at doc.rust-lang.org/error_codes.

With Run, the program’s output appears in Output. If the program reads from the keyboard (like Guess the number), type in the Input field below and press Enter.

The arrow next to Run lets you choose where it runs:

  • Built-in output panel (default): inside Raxorin Studio.
  • External terminal (new window): in a separate terminal window. Useful for programs that draw in the console (like the Game of Life) or use colors and special keys.

You can also run whatever you want from the built-in terminal, for example cargo run -- file.txt to pass arguments to the program.

A test is a function marked with #[test]. If it finishes without a panic, it passes:

src/lib.rs
pub fn double(n: i32) -> i32 {
n * 2
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn doubles() {
assert_eq!(double(21), 42);
}
}

Test runs them all and shows which ones failed, with the expected and the actual value. The #[cfg(test)] module is only compiled for tests: it takes no space in your program. The Geometry and Calculator samples come with tests so you can see how they’re written.

The Debug / Release selector in the toolbar chooses the configuration, like in Visual Studio:

Debug Release
Builds Fast Slower
The program Slower, with debugging information Optimized (it can be 10 to 100 times faster)
Saved in target/debug/ target/release/
For Writing and testing Shipping or measuring performance

Debugging always uses Debug. To produce the final program and share it, use Publish.

Check runs Clippy, which knows hundreds of common patterns and suggests clearer or more efficient ways to write the same thing. For example, it will tell you that if x == true is the same as if x, or that v.len() == 0 is written v.is_empty(). They aren’t errors: your program works the same, but learning from Clippy is one of the best ways to write idiomatic Rust.