Reading Rust

Before you start

Setup

You cannot learn to read Rust deeply without running a compiler. Reading alone produces exactly the fluency illusion this course is built to prevent.

The minimum

A toolchain, a scratch crate, and the habit of checking predictions against rustc rather than against your intuition. Everything else on this page is optional.

You can get started without installing anything: every self-contained snippet in the course has a Run button that compiles it on the official Rust Playground and shows you the real compiler output. Install the toolchain anyway β€” you will want to modify things, and the Playground is someone else's server.

Toolchain

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

Then check it, and make a scratch crate you will use constantly:

rustc --version
cargo new scratch && cd scratch
cargo run

Keep scratch open in an editor for the whole course. Every Predict box on this site is a thing you should paste in and run. The compiler is the oracle β€” that is the entire method.

Editor

Use rust-analyzer. It is not optional for reading unfamiliar code: go-to-definition and inlay type hints are the difference between decoding generic code and reading it.

The commands you will actually use

CommandWhat it is for
cargo checkType-check without generating code. Much faster than build; what you want while iterating.
cargo clippyThe linter. Around 700 lints, many of which teach idiom rather than catch bugs.
rustc --explain E0502Underused. A full explanation of any error code, with examples.
cargo doc --openLocal docs for your project and every dependency, at your exact versions.
cargo tree -i <crate>Why is this dependency here? Inverts the tree to show who pulled it in.
cargo expandSee through macros and derives. Install with cargo install cargo-expand.
cargo bloatWhich generics produced the most binary. Makes monomorphisation concrete.
cargo +nightly miri testDetect undefined behaviour in unsafe code at run time.

Reading tools

This course is about reading, so these matter more here than in most Rust material.

Edition

Use the 2024 edition β€” it is what cargo newgives you on a current toolchain, and it is what the Playground links on this site use. Editions are opt-in language dialects; crates on different editions interoperate fine, so this is a per-crate choice with no ecosystem cost.

One habit worth building

When a Predict box asks whether something compiles and you arecertain, that is exactly when to hit Run. Certainty is where the wrong models hide, and it is whatCalibration is measuring. Commit your answer first, though β€” reading the output before predicting turns the best tool on this site into a spoiler.

Ready? Start with0.1 β€” Why you will feel stupid.