TechLead
Lesson 1 of 28
5 min read
Rust

Introduction to Rust

Learn what Rust is, why companies like AWS, Google, and Discord use it, and get started with rustup, cargo, and your first program.

What is Rust?

Rust is a systems programming language focused on safety, speed, and concurrency. It achieves memory safety without a garbage collector, making it ideal for performance-critical software where reliability is paramount. First released in 2015 by Mozilla Research, Rust has been voted the most admired programming language in Stack Overflow surveys for years running.

Why Rust?

  • Memory Safety: No null pointers, no dangling references, no buffer overflows — guaranteed at compile time
  • Zero-Cost Abstractions: High-level ergonomics with low-level performance — you don't pay for what you don't use
  • Fearless Concurrency: The type system prevents data races before your code ever runs
  • Modern Tooling: Cargo (build system & package manager), rustfmt, clippy, and excellent documentation
  • Growing Ecosystem: Over 140,000 crates on crates.io covering web, CLI, embedded, WASM, and more

Who Uses Rust in Production?

Rust has been adopted by some of the world's largest technology companies for critical infrastructure:

Company Use Case
AWSFirecracker (microVMs), Bottlerocket OS, Lambda runtime
GoogleAndroid OS components, Chrome, Fuchsia OS
DiscordReplaced Go services — reduced tail latency from 300ms to 5ms
CloudflarePingora (HTTP proxy replacing nginx), Workers runtime
MicrosoftWindows kernel components, Azure IoT
MetaSource control (Mononoke), Diem blockchain
DropboxFile sync engine rewritten from Python

Rust vs C++ vs Go

Feature Rust C++ Go
Memory SafetyCompile-time guaranteedManual (error-prone)Garbage collected
PerformanceComparable to C/C++Maximum controlGood, but GC pauses
ConcurrencyCompile-time safeManual (data races possible)Goroutines (runtime safe)
Learning CurveSteep (ownership)Very steepGentle
Package ManagerCargo (excellent)CMake/Conan (fragmented)Go modules

Installing Rust with rustup

rustup is the official Rust toolchain installer. It manages Rust versions and associated tools like cargo, rustfmt, and clippy.

# Install rustup (macOS, Linux, WSL)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Verify installation
rustc --version    # rustc 1.78.0 (or newer)
cargo --version    # cargo 1.78.0
rustup --version   # rustup 1.27.x

# Update Rust to latest stable
rustup update

# Install additional components
rustup component add clippy rustfmt rust-analyzer

Cargo: Rust's Build System & Package Manager

# Create a new project
cargo new hello_rust
cd hello_rust

# Project structure:
# hello_rust/
#   Cargo.toml    # Project manifest (dependencies, metadata)
#   src/
#     main.rs     # Entry point

# Build and run
cargo build          # Compile (debug mode)
cargo run            # Compile and run
cargo build --release # Compile with optimizations
cargo check          # Type-check without producing binary (fast!)
cargo test           # Run tests
cargo doc --open     # Generate and open documentation

Hello, World!

// src/main.rs
fn main() {
    // println! is a macro (note the !)
    println!("Hello, World!");

    // String formatting
    let name = "Rust";
    let year = 2015;
    println!("{name} was first released in {year}");

    // Debug printing
    let numbers = vec![1, 2, 3, 4, 5];
    println!("Numbers: {:?}", numbers);

    // Pretty debug printing
    println!("Numbers: {:#?}", numbers);
}

The Rust Playground

You can try Rust code instantly in your browser at play.rust-lang.org. The playground supports stable, beta, and nightly Rust, and includes popular crates. It's perfect for experimenting and sharing code snippets.

// Try this in the Rust Playground!
fn fibonacci(n: u32) -> u64 {
    match n {
        0 => 0,
        1 => 1,
        _ => fibonacci(n - 1) + fibonacci(n - 2),
    }
}

fn main() {
    for i in 0..10 {
        println!("fib({i}) = {}", fibonacci(i));
    }
}

Key Takeaways

  • ✅ Rust guarantees memory safety at compile time without a garbage collector
  • ✅ Major companies (AWS, Google, Discord, Cloudflare) use Rust in production
  • ✅ Cargo provides an excellent build system, package manager, and project scaffolding
  • ✅ rustup manages toolchains and components like clippy and rustfmt
  • ✅ The Rust Playground lets you experiment in the browser instantly

Continue Learning