Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Why You Will Actually Like Rust

If you only remember one thing: Rust catches at compile time the exact bugs you usually catch in production at 3 a.m.

The one-paragraph pitch

You have probably shipped code that crashed because something was None, or null, or undefined, when you thought it was not. You have probably debugged a race condition that only happened on Tuesdays. You have probably watched a server leak memory and restarted it on a cron job. Rust is a language whose entire personality is “what if we just made those bugs impossible to compile?” That is it. That is the whole pitch.

The bargain

A small amount of friction up front, a large amount of peace later

time on the project → pain other languages rust fight the compiler ship confident code
Rust front-loads the work the compiler does for you. Other languages back-load it onto your on-call rotation.

The four bugs Rust deletes

The same four bugs have eaten more engineering time than every other category combined. Rust removes them at compile time.

The four
  1. Null / None surprise. You think a value is there. It is not. In Rust you cannot even ask for a value without first answering "what if it is missing?"
  2. Data race. Two threads write to the same variable without coordinating. In Rust this is a compile error, not a Heisenbug.
  3. Use-after-free. You free memory, then accidentally read from it. In Rust the compiler will not let that code link.
  4. Silent failure. A function quietly returns a default when something went wrong. In Rust, errors are ordinary values you cannot forget to look at.

Before you read a single chapter, watch the pitch in action: here are the four bugs, and here is the compiler deleting each one.

Interactive simulation (requires JavaScript): the four memory and concurrency bugs — use-after-free, double free, dangling pointers, and data races — each shown with the compile-time error or ownership rule that deletes it in Rust.

## "But is it not famously hard?"

Rust has a reputation for being hard. The reputation is half deserved. The half that is deserved is real: Rust asks you to think about one thing most languages let you ignore — who is allowed to touch a piece of data, and when. That is the idea behind ownership. It is not complicated, it is just new, and like anything new it feels awkward for about a week.

The half that is not deserved is the rest: Rust’s syntax is not weirder than TypeScript’s, its tooling is better than almost any other language’s, its error messages are the best in the industry, and its documentation is excellent. Once the ownership idea clicks — and Part 0 is built to make it click fast — the rest feels like any other modern language, just with fewer 3 a.m. pages.

Who this book is for

Plain English

If you can read JavaScript, Python, or TypeScript without a dictionary, you can read this book. We assume you know what a variable, a function, and an if are. We assume nothing else.

If you have written C or C++, you will move faster through Part 0. If you have not, nothing in Part 0 requires you to.

How to get the most out of it

Three rules.

  1. Run every code example. Every block has a “Run in Playground” link. Click it. Change a number. Re-run it. This costs you thirty seconds per block and saves you thirty minutes of re-reading.
  2. Do not skip the pictures. The SVG figures carry at least half the meaning of this book. The prose is the caption; the picture is the point.
  3. When the compiler shouts at you, read what it said. Rust’s compiler is a senior engineer looking over your shoulder. Its error messages usually tell you exactly which three characters to change. The habit of reading them carefully is the single biggest thing that separates frustrated Rust beginners from happy ones.

Ready? Hello, Rust →