Learn You a Rust for Greater Good!
So you’ve decided to learn Rust. Maybe a friend wouldn’t stop talking about it. Maybe your build at work is segfaulting at 2am and you’d like, just once, for the computer to tell you you’re holding it wrong before it explodes. Maybe somebody on the internet called your favourite language “memory unsafe” and you’d like to respond with something stronger than “you take that back.”
Whatever the reason: welcome. Pour yourself a drink, put on the sweater your grandma made you, and let’s get oxidized.
What is this thing?
It’s a book. A web book. A webook? No. It’s a book on a website, in the cheerful tradition of Learn You a Haskell for Great Good!, to which this site owes most of its personality and roughly 0% of its ML-style type theory.
The pitch is simple: every code example you see, you can run. Edit it. Break it.
Make it print rude words. Click “Run” and it’ll go off and compile against the
real rustc (via play.rust-lang.org) and bring back
the output — errors, panics, and all. The borrow checker will be there. It
wouldn’t miss it.
The table of contents (such as it is)
- CHAPTER 1IntroductionWhat Rust is, why you’d suffer through it, and how to set up the toolchain.
- CHAPTER 2Starting OutYour first function, your first
println!, your first stern look from the compiler. - CHAPTER 3Ownership & BorrowingThe Big One™. Where Rust goes “no, you can’t do that” and is mostly right.
- CHAPTER 4Types & TraitsBelieve the type. Then teach it some manners with traits.
- CHAPTER 5Pattern Matching
matcharms,if let, enums, and other ways to ask “but what KIND of thing is it?” - CHAPTER 6Error Handling
Option,Result,?, and the joy of not throwing. - CHAPTER 7Iterators & ClosuresComing soon.
- CHAPTER 8CollectionsComing soon.
- CHAPTER 9LifetimesComing soon.
- CHAPTER 10Smart PointersComing soon.
- CHAPTER 11Fearless ConcurrencyComing soon.
- CHAPTER 12MacrosComing soon.
A note on the playground
Every editor on this site talks to the official Rust Playground. The first time you Run something it’ll take a half-second or so; after that we cache the result in your tab so re-runs are instant. There’s an ”↗ Playground” button on every editor too — it’ll dump the snippet into a fresh tab over at play.rust-lang.org so you can mess with it without losing your place.
If your internet is down, the editor still works, the highlighting still works, and you can still pretend to compile things with your mouth.
Ready? Onward.