beginner30 minutesLesson 1 of 10

Why Rust?

Discover Rust's core strengths: memory safety without garbage collection, zero-cost abstractions, and fearless concurrency

Why Rust?

Rust is a systems programming language focused on safety, speed, and concurrency. Created by Mozilla and now stewarded by the Rust Foundation, it has been voted the "most loved language" on Stack Overflow surveys for years running.

Memory Safety Without Garbage Collection

Languages fall into two camps:

ApproachExamplesTrade-off
Manual memoryC, C++Full control, but bugs (use-after-free, buffer overflows)
Garbage collectedJava, Go, PythonSafe, but unpredictable pauses and overhead
Ownership-basedRustSafe at compile time, zero runtime overhead

Rust guarantees memory safety at compile time through its ownership system. No null pointer dereferences, no dangling pointers, no buffer overflows — without needing a garbage collector.

Success

Rust's ownership model catches memory bugs at compile time. If it compiles, it's memory-safe — no runtime surprises.

Zero-Cost Abstractions

A zero-cost abstraction means you don't pay for what you don't use, and what you do use couldn't be written faster by hand. Rust's iterators, closures, and generics all compile down to the same efficient machine code as manual implementations.

rust
// This high-level iterator chain... let sum: i32 = (0..100).filter(|x| x % 2 == 0).map(|x| x * 2).sum(); // ...compiles to the same assembly as this hand-written loop let mut sum = 0; let mut i = 0; while i < 100 { if i % 2 == 0 { sum += i * 2; } i += 1; }
ℹ️Note
| Concept | Meaning | |---------|---------| | Zero-cost | Abstractions have no runtime overhead | | Compile-time | The cost is paid during compilation, not execution | | Predictable | No hidden allocations, no garbage collection pauses |

Comparison with C/C++

AspectRustC/C++
Memory safetyGuaranteed by compilerManual (developer responsibility)
Build systemCargo (built-in)CMake, Make, etc. (external)
Package managercrates.io (official)vcpkg, Conan (community)
Learning curveSteep (ownership)Steep (pointers, UB)
NullOption<T> (no null)NULL / nullptr
Error handlingResult<T, E>Return codes / exceptions
ConcurrencyData-race free by defaultManual (pthreads, mutexes)
rust
// C: int* ptr = malloc(sizeof(int)); free(ptr); // Rust: no manual free needed let ptr = Box::new(42); // Automatically freed when ptr goes out of scope

Comparison with Go

AspectRustGo
Memory managementOwnership (compile-time)GC (runtime)
Abstraction costZero-costSome GC overhead
Concurrency modelOwnership + Send/Sync traitsGoroutines + channels
Compilation speedSlowerFast
Binary sizeSmall, no runtimeStatic binary, includes GC
Use caseSystems, embedded, WASMWeb services, CLI tools

The Rust Ecosystem

Rustup — Toolchain Manager

bash
rustup update # Update Rust rustup default nightly # Switch to nightly

Cargo — Build System and Package Manager

bash
cargo new my_project cargo build cargo run cargo test cargo doc --open

Crates.io

The Rust package registry hosts over 150,000 crates:

  • serde — Serialization/deserialization
  • tokio — Async runtime
  • rayon — Data parallelism
  • clap — CLI argument parsing
  • reqwest — HTTP client

Fearless Concurrency

Rust's type system prevents data races at compile time. The Send and Sync traits (auto-derived when safe) ensure you can't accidentally share mutable state across threads.

rust
use std::thread; fn main() { let data = vec![1, 2, 3]; // This won't compile — trying to share non-Sync data // thread::spawn(|| println!("{:?}", data)); // Move ownership to the closure thread::spawn(move || println!("{:?}", data)).join().unwrap(); }

Where Rust Excels

  • WebAssembly — Compile to WASM for near-native speed in the browser
  • Embedded systems — No runtime, predictable performance
  • CLI tools — Fast, small binaries (bat, ripgrep, fd, alacritty)
  • Web backends — Actix-web, Axum, Rocket frameworks
  • Game engines — Bevy, Godot bindings
  • Operating systems — Redox, kernel modules
  • Blockchain — Solana, Polkadot, Near
⚠️Warning

Rust has a steep learning curve. The ownership system and borrow checker will feel restrictive at first. Persist through the first few weeks — the compiler errors are actually excellent teaching tools.

Companies Using Rust

CompanyUse Case
MozillaFirefox CSS engine (Servo/Quantum)
MicrosoftWindows kernel components
GoogleAndroid (AOSP), Fuchsia OS
AmazonAWS infrastructure (Firecracker VMs)
MetaSource control (Mononoke), Diem blockchain
DiscordBackend services, client performance
FigmaReal-time collaboration engine
CloudflarePingora, edge compute infrastructure

Practice Questions

  1. What three guarantees does Rust's ownership system provide at compile time?
  2. What does "zero-cost abstraction" mean in Rust?
  3. How is Rust's memory management different from Java's GC and C's manual management?
  4. What command creates a new Rust project?
  5. What is crates.io?
  6. Compare Rust's error handling with C++ exceptions.
  7. What does "fearless concurrency" mean?
  8. Name three companies using Rust in production.
  9. What problem does Rust solve that C/C++ have struggled with for decades?
  10. How does Rust's approach to null differ from most languages?
Progress10%