Basics & Toolchain
Rust is a compiled language. You write a program as text, and the compiler checks it and translates it into an executable file that runs without Rust itself. Working with the language starts with three tools: rustup installs and updates the others, rustc compiles, and cargo creates the project, builds, runs and checks it. In practice almost every command starts with the word cargo. Cargo distinguishes two builds: a debug one, which compiles fast, and a release one, which runs fast.
The first program prints a line with the println! macro. The exclamation mark is not decoration. The macro checks the format string at build time, so an extra argument or a value that cannot be printed with {} is a compile error rather than a surprise at run time.
Strictness is the defining trait of the Rust compiler. Much of what surfaces while a program runs in other languages is stopped here before launch, and the error message explains what is wrong and suggests a fix. That is why a newcomer's first skill is reading these messages rather than fighting them. This topic walks the start layer by layer: the tools, a Cargo project, printing and formatting, compiler errors.
Topic map
- The Rust Toolchain —
rustupinstalls and updates,rustccompiles,cargoruns the project; thestable,betaandnightlychannels; edition 2024 is a set of language rules, not a compiler version. - A Cargo Project —
cargo newcreatesCargo.tomlandsrc/main.rs;build,runandcheck; a debug build versus--release; everything built lives intarget/. - Printing and Formatting —
println!,print!,eprintln!andformat!;{}versus{:?}and{:#?};{x}right in the string; width and precision; why it is a macro. - Reading Compiler Errors — the
error[E0382]code, the location after-->, thehelp:andnote:hints,rustc --explain; the first error matters more than the rest; warnings do not stop the build.
Common mistakes and traps
| Mistake | Consequence |
|---|---|
| Measuring the speed of a debug build | Without optimizations a program can be tens of times slower; measurements are made with --release |
Expecting a finished program from cargo check | check skips machine-code generation and linking, so there is no executable |
| Confusing the edition with the compiler version | The edition is chosen in Cargo.toml; rustc 1.99 builds both 2015 and 2024 code |
Building a file with a bare rustc main.rs | Without --edition the 2015 edition applies, and code written to 2024 rules may fail to build |
Printing a Vec or your own struct with {} | Error E0277: the type has no Display; you need {:?}, and a struct also needs #[derive(Debug)] |
Writing an expression in the braces: {p.x}, {a + 1} | Does not compile: only a variable name is allowed in the braces |
| Reading compiler output from the end and skipping warnings | The cause is in the first error, and a warning often points to a real slip |
Why it matters in interviews
This topic opens the junior section of a Rust interview. The commands are easy to learn, so interviewers ask what stands behind them: what cargo check skips, how a debug build differs from a release build, and why println! is a macro.
What interviewers usually check:
- What
rustup,rustcandcargodo, and how an edition differs from a compiler version. - What
cargo new,build,runandcheckdo, and what exactlycheckskips. - How a debug build differs from
--release: optimizations, overflow checks, the folders intarget/. - Why
println!is a macro, and how{}differs from{:?}and{:#?}. - How to read an
error[E…]message and whatrustc --explaingives you.