RustRust Introduction

Introduction to Rust

Rust is a systems programming language that runs blazingly fast, prevents nearly every class of memory bug at compile time, and makes concurrent programming safe and approachable. It sits in the same performance tier as C and C++, yet it eliminates entire categories of security vulnerabilities — dangling pointers, use-after-free, data races, buffer overflows — before your program ever runs.

The result is software that is both fast and correct by construction — something that was previously considered very difficult to achieve without a garbage collector or heroic developer discipline.

A brief history

Rust did not appear overnight. Its origins trace back to 2006, when Graydon Hoare, a Mozilla engineer, started the language as a personal project. He was frustrated by a recurring class of memory bugs in C and C++ that caused endless security incidents — and wanted to prove that a language could enforce memory safety without sacrificing performance.

  • 2006 — Graydon Hoare begins Rust as a personal research project.

  • 2009 — Mozilla officially sponsors development, seeing potential for a safer systems language to write browser engine components.

  • 2010 — Rust is publicly announced. The self-hosting compiler (written in Rust) begins development.

  • 2012 — Servo, a next-generation browser engine written in Rust, is announced by Mozilla.

  • 2015 — Rust 1.0 is released — the first stable version, marking a commitment to backwards compatibility.

  • 2016–2020 — Rust is voted the "most loved programming language" in the Stack Overflow Developer Survey every single year.

  • 2021 — The Rust Foundation is established, with founding members including AWS, Google, Huawei, Microsoft, and Mozilla.

  • 2022 — Rust becomes the second official language of the Linux kernel after C — a historic milestone for a language that young.

  • 2023–present — Major adoption in Windows, Chrome, Android, and cloud infrastructure continues to accelerate.

The three pillars of Rust

The Rust team describes the language around three core values. Every design decision — even the controversial ones — traces back to at least one of these:

  • Performance. Rust compiles to native machine code with no runtime overhead. There is no garbage collector, no virtual machine, no interpreter. Rust programs can be as fast as — and often faster than — equivalent C or C++ code.

  • Reliability. The compiler is your co-pilot. Type errors, null dereferences, dangling pointers, data races — the vast majority of bugs that plague systems languages are caught at compile time in Rust, not at runtime in production.

  • Productivity. A strict compiler alone is not enough. Rust ships with Cargo (its build system and package manager), rustfmt (automatic code formatting), Clippy (a linting engine with hundreds of actionable hints), and rustdoc (documentation that runs as tests). The whole toolchain is first-class.

Why memory safety matters
The US National Security Agency (NSA), the White House Office of the National Cyber Director, and CISA have all published guidance recommending that new systems software be written in memory-safe languages. Memory safety bugs account for roughly 70% of all critical security vulnerabilities in major software products. Rust is the only systems language that provides this guarantee without a garbage collector runtime.
Who uses Rust in production?

Rust has moved decisively from research project to industry staple. Some notable adopters:

  • Linux Kernel — Rust is the second language accepted in the kernel (since 6.1), used for new driver development.

  • Google Android — New low-level Android components are written in Rust. Google reports a dramatic reduction in memory safety vulnerabilities.

  • Microsoft Windows — Microsoft is rewriting core Windows components in Rust to eliminate decades-old vulnerability classes.

  • Google Chrome — The Chromium team uses Rust for security-critical components.

  • AWS — Firecracker (the microVM technology behind AWS Lambda) is written entirely in Rust.

  • Cloudflare — Their edge networking stack and the Pingora proxy (replacing NGINX) are built in Rust.

  • Discord — Rewrote their Go services to Rust and achieved 10x lower CPU usage and near-zero latency spikes.

  • Dropbox — Rewrote their file sync engine in Rust, citing significant performance and reliability gains.

  • Meta — Uses Rust for internal tooling and performance-critical backend services.

  • npm / GitHub — Rust powers parts of the package registry and source-hosting infrastructure.

Ownership: the big idea

The feature that makes Rust unique is its ownership system — a set of compile-time rules that govern how memory is allocated and freed. You do not call malloc and free. You do not wait for a garbage collector. Instead, the compiler tracks exactly which variable owns each piece of memory, and frees it automatically the instant it goes out of scope.

Three rules sum up the entire ownership model:

  1. Every value in Rust has exactly one owner — a variable that is responsible for it.

  2. There can only be one owner at a time. When ownership is transferred (moved), the old variable can no longer be used.

  3. When the owner goes out of scope, the value is dropped and its memory is freed automatically.

Rust builds on top of ownership with borrowing (shared &T references and exclusive &mut T references) and lifetimes (compile-time proofs that references never outlive the data they point to). Together, these three concepts form the borrow checker — the part of the compiler that eliminates memory bugs at zero runtime cost.

Tip
Do not worry if ownership feels abstract right now. This tutorial covers it step by step with concrete examples. For now, just know that the compiler — not you, and not a runtime — is in charge of memory.
What can you build with Rust?
  • Systems software — operating systems, device drivers, hypervisors, embedded firmware.

  • Command-line tools — Rust CLIs like ripgrep, bat, fd, and exa are significantly faster than the Unix tools they replace.

  • Web backends — frameworks like Axum and Actix-Web power high-throughput HTTP APIs.

  • WebAssembly — Rust is the most popular language for compiling to Wasm, enabling near-native speed in browsers.

  • Game enginesBevy is a data-driven game engine built entirely in Rust.

  • Networking — proxies, load balancers, DNS servers, TLS libraries.

  • Databases — TiKV (the storage layer of TiDB) and Neon (serverless Postgres) are written in Rust.

  • Blockchain and cryptography — Solana, Polkadot, and many other protocols use Rust for their core runtimes.

  • Embedded and IoT — Rust runs on microcontrollers with as little as a few KB of RAM.

Hello, World!

Every Rust journey starts the same way. If you have Rust installed (see the Install page), create a new project and run it:

Create a new Rust project

Bash
cargo new hello_world
cd hello_world

Cargo creates a src/main.rs file with a Hello World already written inside:

src/main.rs

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

Run it with a single command:

Bash
cargo run
   Compiling hello_world v0.1.0 (./hello_world)
    Finished dev [unoptimized + debuginfo] target(s) in 0.42s
     Running `target/debug/hello_world`
Hello, World!

A few things to notice even in this tiny program:

  • fn main() — every executable Rust program starts from a main function.

  • println! — the exclamation mark means this is a macro, not a regular function call. Rust macros are expanded at compile time and can accept variable numbers of arguments.

  • Statements end with a semicolon ;. The last expression in a block that has no semicolon is the return value of that block.

  • Indentation is 4 spaces — enforced by rustfmt, the official formatter.

  • cargo run compiled and ran the program in one step. Behind the scenes it called rustc (the Rust compiler) for you.

Rust vs the alternatives

Language

Memory Safety

GC / Runtime

Speed

Best for

Rust

Compile-time guaranteed

None

C-level

Systems, safety-critical, WebAssembly

C

Manual (none enforced)

None

C-level

Legacy systems, low-level hardware

C++

Manual (some tools help)

None

C-level

Game engines, embedded, existing C++ codebases

Go

Runtime (GC)

GC + goroutine runtime

Very fast

Servers, CLIs, DevOps tooling

Java

Runtime (GC)

JVM

Fast

Enterprise backends, Android apps

Python

Runtime (GC)

CPython runtime

Slow (use Rust extensions!)

Scripts, data science, glue code

Is Rust hard to learn?

Rust has a reputation for a steep learning curve, and that reputation is partially earned. The ownership and borrowing system introduces concepts that do not exist in other mainstream languages, and the compiler is strict — it will refuse to compile programs that would be accepted by C, Go, or Python.

But the curve is front-loaded. Once you internalize ownership — usually after a few weeks of consistent practice — you stop fighting the compiler and start working with it. The errors that used to feel cryptic start to feel like a helpful pair programmer pointing out exactly what would have gone wrong at runtime in production.

Warning
Expect the first week or two with Rust to feel frustrating. The borrow checker will reject code that seems like it should work. That is completely normal — every Rust programmer goes through it. Push through. The payoff in confidence and correctness is substantial.
Success
The Stack Overflow Developer Survey has named Rust the most admired programming language for nine consecutive years (2016–2024). Developers who learn it overwhelmingly report wanting to keep using it.
What this tutorial covers
  • Getting started — installing Rust with rustup, first programs, Cargo basics.

  • Core language — variables, types, functions, control flow, pattern matching.

  • Ownership and borrowing — the rules, common pitfalls, and how to think about them.

  • Structs and enums — defining your own data types, implementing methods.

  • Error handlingResult, Option, the ? operator, and panic.

  • CollectionsVec, HashMap, String, iterators and closures.

  • Traits and generics — polymorphism the Rust way.

  • Lifetimes — writing functions and structs that hold references safely.

  • Concurrency — threads, Mutex, Arc, async/await with Tokio.

  • Cargo deep dive — workspaces, features, publishing to crates.io.

Tip
The best way to learn Rust is to write Rust. Open a `cargo new playground` project and experiment alongside every page of this tutorial. The compiler error messages are some of the most informative in any language — read them carefully and they will teach you Rust faster than any book.