Rust Introduction

What Rust is, why it exists, and how to install it and run your first program with Cargo.

What is Rust?

Rust is a systems programming language first released by Mozilla Research in 2010 (reaching a stable 1.0 in 2015), designed to let you write low-level, high-performance code — the kind traditionally written in C or C++ — without the memory bugs those languages are notorious for.

Its central idea is memory safety without a garbage collector. Rust's compiler enforces a set of ownership rules at compile time that eliminate entire categories of bugs — dangling pointers, data races, buffer overflows, use-after-free — before the program ever runs, at zero runtime cost.

Rust
fn main() {
    println!("Hello, Rust!");
}

Why use Rust?

  • Memory safety without a GC — the borrow checker (covered in depth in the next pages of this track) catches memory errors at compile time instead of leaving them to a garbage collector or to the programmer's discipline.
  • Performance — Rust compiles to native machine code via LLVM, with no runtime or garbage collector pausing your program, putting it in the same performance class as C and C++.
  • Fearless concurrency — the same ownership rules that prevent memory bugs also prevent data races at compile time, so concurrent code is far harder to get wrong than in most languages.
  • Modern toolingcargo (Rust's build tool and package manager) handles dependencies, builds, tests, formatting and documentation generation out of the box, no separate tools required.
  • Interoperability — Rust can call into and be called from C code, and compiles cleanly to WebAssembly, making it useful in browsers, embedded devices and existing native codebases alike.
  • Consistently voted "most loved language" — Rust has topped Stack Overflow's developer survey for multiple years running, largely because of the compiler's genuinely helpful error messages.

Installing Rust

Rust is installed via rustup, the official toolchain installer and version manager:

Bash
# macOS / Linux
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Windows — download and run rustup-init.exe from https://rustup.rs

rustup installs the Rust compiler (rustc), the package manager and build tool (cargo), and lets you switch between stable, beta and nightly toolchains, and between versions, at any time:

Bash
rustc --version   # e.g. rustc 1.80.0 (stable)
cargo --version   # e.g. cargo 1.80.0
rustup update     # keep your toolchain current

Your first project with Cargo

Almost nobody compiles a single file with rustc directly in real projects — Cargo manages the whole project lifecycle:

Bash
cargo new hello_rust
cd hello_rust
cargo run

cargo new scaffolds a project with this structure:

Plaintext
hello_rust/
├── Cargo.toml      # project metadata + dependencies ("crates")
└── src/
    └── main.rs     # entry point — fn main() is where execution starts
Rust
// src/main.rs (generated automatically by `cargo new`)
fn main() {
    println!("Hello, world!");
}

cargo run compiles the project (if it changed) and runs the resulting binary in one step. Two other commands you'll use constantly:

Bash
cargo build            # compile only, debug profile — output in target/debug/
cargo build --release  # compile with full optimizations — output in target/release/
cargo check            # type-check without producing a binary — much faster, great while editing

Real-world example

Rust powers performance- and safety-critical infrastructure across the industry: large parts of the Linux kernel now accept Rust code, Firefox's CSS engine (Servo/Stylo) is written in Rust, Dropbox rewrote its storage backend in it, Discord uses it for latency-sensitive services, and AWS built its Firecracker microVM technology (which powers Lambda) in Rust specifically for its memory-safety guarantees under untrusted workloads.

Common mistakes

  • Trying to fight the compiler by adding .clone() everywhere to make ownership errors disappear, instead of understanding why the borrow checker is complaining (the next page in this track covers this properly).
  • Skipping cargo check while iterating and running the full cargo build every time, which is noticeably slower for large projects.
  • Assuming Rust is only for systems programming — it's also a very productive choice for CLIs, web backends (Axum, Actix), and WebAssembly.

Interview questions

Q: What is Rust's core selling point compared to C++? Memory safety guaranteed at compile time — through ownership, borrowing and lifetimes — without sacrificing C++'s zero-cost, garbage-collector-free performance. Most memory bugs that would be runtime crashes or security vulnerabilities in C++ simply fail to compile in Rust.

Q: What does "zero-cost abstraction" mean in the context of Rust? That a high-level, safe abstraction (an iterator, a generic function, an Option<T>) compiles down to code just as efficient as the hand-written low-level equivalent — you don't pay a runtime performance penalty for writing safer, more expressive code.