Deep Dive: egui/eframe for instant UIs — why Immediate Mode fits system languages, State management with Rust's ownership, Layout & Style, Custom painting, and when Retained Mode is the better choice.
Deep dive: atomic operations, memory orderings, and CAS loops — tools without locks but with sharper contracts. When atomics shine and when the mutex stays.
Rust is a systems language that catches memory errors and data races at compile time — not at runtime with a garbage collector. The compiler checks every memory access; if it compiles, it's safe. That costs some time at build, but the finished program runs without pauses and without leaks.
Why can Rust do this without a garbage collector?
Most memory bugs come from aliasing + mutation: two pointers to the same memory, and at least one writes through them. C and C++ allow this freely and hope you keep it straight. A garbage collector (GC) fixes the symptom at runtime: it delays frees and scans memory in the background — a runtime cost, and the reason GC'd languages pause.
Rust does the opposite: it makes dangerous aliasing impossible to express. Every value has exactly one owner, and any other access must be a checked borrow. If your code would double-free, use-after-free, or race, it does not compile — the compiler proves the memory handling is safe before the program runs.
Because safety is proven at compile time, the runtime needs no GC and no scan: memory is freed exactly when the owner goes out of scope — deterministic, no pauses. That's the trade: you convince the borrow checker, and you get back deterministic cleanup.
You'll write your first borrow-checker error in Module 3 (Ownership). For now remember one line: the compiler checks it, so the runtime doesn't have to.
The official way is rustup — a toolchain manager that installs and keeps up to date
the compiler rustc, the build tool cargo, and the standard library documentation:
# Linux / macOS / WSL
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Windows: rustup-init.exe from https://rustup.rs
Then check:
rustc --version
cargo --version
Check: What is rustup responsible for?
Answer: Install and manage toolchains (rustc, cargo, docs)
rustup is the toolchain manager: installation, updates, and version switching (stable/nightly). Publishing is done by cargo publish, formatting by rustfmt.
Key points:
⚠ Common mistake: Right after installation the shell may report
command not found: cargoeven though rustup ran fine. The reason:~/.cargo/binisn't on the open terminal'sPATHyet — open a new terminal or runsource ~/.cargo/envonce, and it works.
Takeaways:
A Rust project is called a crate. Cargo creates it, builds it, tests it:
cargo new hello_rust
cd hello_rust
cargo run # build + run
cargo check # only type-check, no binary — very fast
cargo build # build, binary in target/debug/
cargo check is your constant companion while writing: it goes through parsing,
type checking, and the borrow checker, but does not produce an executable program —
which is why it's significantly faster than cargo build.
Check vs. Build
cargo check = entire compiler pipeline except code generation and linking.
Perfect feedback loop in the editor (rust-analyzer uses exactly that). You only need cargo build
when you actually want to start the program.
Check: Why do you usually use cargo check instead of cargo build while writing?
Answer: check type-checks without producing a binary — faster
Code generation + linking are the most expensive steps. check skips them and still gives you all compiler errors.
⚠ Common mistake: Hand-creating
main.rsand then runningcargo runonly gets youerror: could not find Cargo.toml. Cargo commands work exclusively inside a directory with a manifest — that's why you always create projects withcargo new.
After cargo new hello you get:
hello/
├── Cargo.toml # manifest: name, version, dependencies
├── src/
│ └── main.rs # program entry point
└── target/ # build artifacts (excluded from git via .gitignore)
Cargo.toml is the manifest — dependencies go under [dependencies].target/ holds all build artifacts; cargo new automatically creates a .gitignore for it.cargo check only checks (fast feedback), cargo build creates the debug binary, cargo run builds and runs, cargo build --release builds optimized into target/release/.Check: Why does target/ never end up in the git repository?
Answer: cargo new automatically creates a .gitignore with /target
Build artifacts are reproducible and do not belong in the repo — the .gitignore created by cargo new excludes /target.
Takeaways:
src/main.rs after cargo new:
fn main() {
println!("Hello, world!");
}
fn main() — entry point of every executable programprintln! — a macro (recognizable by the !), not a function callRust knows two formatting styles — inline by variable name and positional:
fn main() {
let name = "Rust";
println!("Hello, {name}!"); // inline: uses the binding `name`
// → Hello, Rust!
println!("{} + {} = {}", 1, 2, 3); // positional: in order
// → 1 + 2 = 3
}
Both lines print Hello, Rust! and 1 + 2 = 3 respectively. Inline formatting
works with any binding in scope — super readable, which is why it's the everyday style in modern Rust.
Why an exclamation mark?
println! is a macro: the compiler translates the format string into real code at compile time.
That's why a typo in the placeholder doesn't hit you at runtime, but immediately during compilation.
Scenario: First steps as a team
Check: What happens if you write println!("Hello, {name}!") and name does not exist?
Answer: Compile error: the compiler does not know name
println! is a macro — the compiler checks the format string at compile time. An unknown placeholder is a compile error, not a runtime problem.
⚠ Common mistake: Mixing up placeholders and arguments — say
println!("{} + {}", a)— never prints garbage at runtime; it's a compile error. The macro matches{}placeholders against the arguments at compile time and also flags typos like{nmae}as an unknown binding.
Takeaways:
Variables are immutable by default:
fn main() {
let x = 5;
// x = 6; // ❌ E0384: cannot assign twice to immutable variable
let mut y = 5;
y = 6; // ✅ explicitly mutable
println!("{x} {y}");
// → 5 6
}
This is a design decision, not paternalism: immutability is the norm, mutability must be written out — anyone reading code immediately sees where something can change.
A block in curly braces evaluates to its last expression — without a semicolon:
fn main() {
let y = {
let a = 2;
a * 3 // no semicolon → value of the block
};
println!("{y}"); // 6
}
Exactly this principle later makes function bodies, if expressions, and match into value providers. The semicolon in Rust is not a line ending, but an operator that turns an expression into a statement (and discards the value).
Check: What is the value of let y = { let a = 2; a * 3 };?
Answer: 6 — the last expression without a semicolon is the value
A block evaluates to its last expression without a semicolon. a * 3 has no semicolon, so 6 is the value of the block.
⚠ Common mistake:
let mut count = 0;followed bycount = "done";doesn't compile —mutmakes a binding mutable but never changes its type. When a different type sits behind the=, the compiler reportsmismatched types; the fix is a freshletbinding, notmut.
Takeaways:
Course navigation: All 27 modules · Module 2 →