R Rust by Evidence PDF

Introduction: Let the Compiler Show Its Work

Rust is easiest to learn when you stop treating compiler errors as interruptions. They are observations about a program: a value moved here, a reference must remain valid there, or a generic function asked for an operation it never required.

This book teaches those relationships through short predictions. Each chapter follows the same loop:

  1. Read a small program.
  2. Predict whether it compiles or what it prints.
  3. Inspect the actual result.
  4. Build a working mental model.
  5. Refine that model into the precise rule.
  6. Compare two valid fixes.
  7. Solve one variation.

Do not merely read the snippets. Put them in src/main.rs and run cargo check or cargo run. For deliberate failures, read the first relevant diagnostic before looking at the answer.

The six questions

Most of the book can be navigated with six questions:

These are more useful than memorizing individual error codes. They transfer from tiny exercises to real programs.

Setup

Install stable Rust with rustup, then verify:

$ rustc --version
rustc 1.92.0 (ded5c06cf 2025-12-08)
$ cargo --version
cargo 1.92.0 (344c4567c 2025-10-21)

Create a scratch program:

$ cargo new rust-scratch
$ cd rust-scratch
$ cargo run

Use these commands throughout:

The companion crate at the root of this repository contains corrected examples and one integrated test. It deliberately has no dependencies. The standard library is enough to learn the language rules.

What this book does not do

It does not survey every standard-library API, teach a web framework, or prescribe an application architecture. Those subjects change and are better learned when a project requires them. The goal here is durable: make Rust's ownership, type, and concurrency rules predictable.

Start with Part I even if you already know another systems language. Rust references are not merely pointers with friendlier syntax; their types encode aliasing and lifetime constraints that shape APIs throughout the rest of the language.