Basics & Syntax
Why Rust?
Section titled “Why Rust?”Rust is a systems programming language designed around three goals:
- Memory safety — the compiler guarantees freedom from null-pointer dereferences, use-after-free bugs, and data races, entirely at compile time.
- Performance — Rust compiles to native machine code with no runtime overhead. There is no garbage collector, no virtual machine, no interpreter.
- Fearless concurrency — the same ownership rules that prevent memory bugs also prevent data races across threads.
The key insight is that Rust achieves these guarantees through the borrow checker — a piece of the compiler that enforces ownership and lifetime rules before your program ever runs. If it compiles, it is memory-safe.
What This Module Covers
Section titled “What This Module Covers”| Lesson | Concept |
|---|---|
| Variables & Mutability | let, mut, shadowing, const |
| Data Types | Scalars, tuples, arrays, type inference |
| Functions | fn, parameters, return types, expressions vs statements |
| Control Flow | if as an expression, loop, while, for, ranges |
A First Rust Program
Section titled “A First Rust Program”Every Rust binary starts from fn main(). The println! macro writes formatted text to standard output. Types are inferred by the compiler when they are unambiguous — you do not need to annotate every variable.
fn main() { println!("Rust guarantees memory safety at compile time."); println!("No garbage collector. No null pointer exceptions."); println!("Zero-cost abstractions. Systems-level performance.");
let x: i32 = 42; let name = "Rust"; println!("x = {}, name = {}", x, name);}The {} in format strings are placeholders — the macro substitutes the corresponding argument value at runtime.
fn main() { println!("Rust guarantees memory safety at compile time."); println!("No garbage collector. No null pointer exceptions."); println!("Zero-cost abstractions. Systems-level performance.");
let x: i32 = 42; let name = "Rust"; println!("x = {}, name = {}", x, name);}Compiling…