Hello, Rust!
Rust is a systems language that gives you memory safety without a garbage collector breathing down your neck. The trick? An ownership system — compile-time rules that erase use-after-free, double-free, and data races before your binary ever boots.
Your First Rust Program
fn main() { println!("Hello, Rust!");}fn main()is the entry point, same as in C.println!is a macro — that's what the!is telling you — and it writes to stdout.- The last expression in a block, sans semicolon, becomes the block's value.
Run it, then make it yours. The second half shows that last bullet in action: the inner block's final line has no semicolon, so its value lands in answer.
Compilation
rustc hello.rs./helloOr with Cargo, Rust's build tool and package manager:
cargo new hello-projectcd hello-projectcargo runEither way, the same pipeline runs underneath. rustc does the Rust-specific work up front (macros, type checking, the borrow checker), then hands an intermediate form to LLVM, the same backend Clang uses for C. LLVM optimises it and emits machine code into an object file, and a system linker stitches that together with the standard library into an executable:
All the safety checks live in that second box and leave nothing behind in the binary. Module 7, What Your Rust Code Does, opens the output up with a disassembler to prove it.
Rust's compiler is notoriously strict — it intercepts at compile time what C and C++ leave for the segfault. The error messages have grown into something rare in this industry: actually helpful. They explain what broke, why it broke, and frequently hand you a patch. Read them as tutoring, not nagging.
Variables
Variables are immutable by default:
let x = 5;// x = 6; // ERROR: cannot assign twice to immutable variable
let mut y = 5;y = 6; // OK: y is declared as mutableTypes
Rust has strong, static typing with inference:
let x: i32 = 42; // explicit typelet y = 42; // inferred as i32let pi: f64 = 3.14159;let flag: bool = true;let ch: char = 'A';let name: &str = "Alice";let owned: String = String::from("Alice");Why Rust for Low-Level Learning?
Rust hands you the same control C does — manual memory layout, zero-cost abstractions, no GC — and the compiler bins the bugs that turn C into a footgun:
- No null pointers; Rust models absence with
Option<T>. - No dangling pointers; the borrow checker refuses to let you have them.
- No data races; the type system enforces it across threads.
- No buffer overflows; bounds checks are the default and you opt out, not in.
By the end of this track you'll have built a command-line network tool, picking up Rust's quirks along the way.