Seven Rust books that don't suck

Seven Rust books that don't suck

What are the books that every aspiring Rust programmer should read, and which should you read first? Don’t worry, I’ve got you covered. Here’s my selection of the best Rust books I’ve read, with some notes on what I enjoyed about them, and what each one can help you learn.

You might also be interested in my Rust mentoring sessions—I’ve found that individual, one-to-one coaching and expert instruction is an ideal complement to learning from books, and I’ve taught Rust and Go to hundreds of students who say it works for them, too. Contact me if you’d like to learn more.

The Rust Programming Language

Of course, right? It’s literally The Book. Everybody should read this first when getting started with Rust. It’s a comprehensive, though not particularly deep, guide to the Rust language, the tools you’ll need to start writing Rust, and some key parts of the standard library.

Steve Klabnik and Carol Nichols (plus countless others from the Rust community) have made this book a labour of love, and it’s the perfect introduction to the language: clear, helpful, and full of well-written examples. You can read the complete text of The Rust Programming Language online, but if you prefer paper books, the print edition from No Starch Press is beautifully-produced, and something every Rustacean would be proud to own.

It’s probably not a good idea to try to read The Rust Programming Language all in one sitting, though of course you can if you like. There’s simply too much to absorb and make sense of. You’re better off reading, say, the first five or six chapters, and then trying to write a few simple Rust programs yourself to apply what you’ve just learned.

This will be demanding enough, don’t worry! Once you’ve wrestled with the borrow checker a little, you can come back to the book and read another chapter, try out the things it describes, go on to the next, and so forth. Once you’ve worked your way through the whole book, running all the examples and attempting some of the exercises, you’ll be very well-placed to start writing more challenging programs.

At that point, you’ll be wondering what to read next…

Effective Rust

Effective Rust is the ideal thing to read next, after the book. Once you’ve learned about the various bits of Rust syntax and what they mean, and a few key concepts such as references, traits, and iterators, you might well ask, “So what do I do with all this stuff? How do I actually use Rust to write programs that solve real problems?”

David Drysdale’s excellent book answers exactly this question, with dozens of practical tips and explanations. It’s like pairing with an expert Rustacean, who can lean over and say things like “Try using an iterator instead of a loop,” or “Here’s where it makes sense to use a macro, and where it doesn’t”.

The book is packed with good advice on how to speak Rust like a native, and it also offers some great jumping-off points for further learning: for example, David suggests you read through all the Clippy lints. This is an excellent tip I’m now passing on to my own students.

You can read Effective Rust online, or buy the very well-presented O’Reilly print edition, just as you prefer.

Rust for Rustaceans

Jon Gjengset is a well-known Rust educator with lots of live-coding videos and streams, and it turns out he’s also an extremely good writer. Rust for Rustaceans is absolutely packed with information, and it’s never afraid to get extremely technical, but the text is clear, crisp, and incisive throughout.

The book’s subtitle, Idiomatic Programming for Experienced Developers, captures perfectly what it’s about. Indeed, the main title was originally Intermediate Rust, which is pretty accurate, too, but I can see why Jon changed it: Rust for Rustaceans is much catchier.

The focus is very much on how to write code in what we might call a Rustaceous way: using the language’s strengths and leaning into them, rather than trying to import patterns from other languages that don’t really work in Rust. There’s a lot of excellent material about how to design APIs that play well with Rust, for example, and how to use the richness of the type and trait system to fit your program neatly into the problem domain.

As great as Rust is, it doesn’t always make the best first impression on people. When you look at code examples, they can seem a bit over-complex and syntactically verbose, and that’s completely understandable. Once you start to pick your way through the forest of angle brackets, though, and discover the core ideas of Rust, you’ll find it’s actually a rather elegant language: perhaps even a beautiful one. At least, I think so.

Jon Gjengset evidently feels the same way, and his book does a terrific job of communicating just why Rust is so neat. This is another book that I’ll always want to keep on my bookshelf, to dip into for interesting tips and titbits, and to re-read every few months to extract yet more value from it.

Programming Rust

The only word for Programming Rust is “magisterial”: at over 700 pages, it’s not a book to be taken lightly, in any sense of the word. However, while there is a fair amount of overlap with other books such as The Rust Programming Language and Rust for Rustaceans, it does contain an awful lot of value.

Programming Rust goes through everything in the language and standard library very methodically and comprehensively, explaining every feature or method, how it works, and when to use it. It has the space and time to go into a lot more depth than the book, which is welcome.

The section on parallel and async programming is particularly useful, with some very detailed examples. In general, I’d put this book somewhere between The Rust Programming Language and The Rust Reference; it aims to be both broad and deep, covering everything a working Rust programmer could conceivably want to know in a single volume.

It’s not the book I’d choose as an introduction to the language, of course, and if you’ve already read The Book, Effective Rust, and Rust for Rustaceans, by the time you reach Programming Rust you’ll find a lot of material that’s now fairly familiar. There’s plenty more that’s new, though, and I think it’s really helpful to have a book that covers some of the lesser-known material, too.

Some of the examples are a little distractingly quirky, but I completely understand the authors’ desire to have a little fun, especially after the first thousand pages or so. It’s very hard to design code examples that are clear, informative, focused, realistic, and interesting, and in general they do a fantastic job of this.

Rust in Action

There are many Rust books, as we’ve already seen, and for another one to be worth reading I think it has to offer something different to all the others. Tim McNamara’s Rust in Action definitely does that.

In the first place, it doesn’t attempt to be an introductory Rust book; that ground is already well-covered. Nor does it repeat material to be found in books like Rust for Rustaceans or Programming Rust. Instead, Tim’s teaching style is to develop a number of sophisticated Rust programs on relatively advanced topics, such as the bitwise layout of floating-point numbers, emulating a simple CPU, inspecting a process’s virtual memory map via the Windows API, and so on.

Later, we’ll learn about networking by manipulating raw TCP and UDP packets, talking to DNS servers, writing an NTP client, procedurally generating images from hash digests, and quite a few other interesting projects that you won’t find in other books. Anything else? Oh yes, we’ll write a bare-metal operating system from scratch. So, no biggie. (“A bit of a role-playing game is added for light relief,” says Tim, engagingly.)

While it’s immensely fun to read, then, Rust in Action is by no means the first Rust book I would recommend to a beginner, nor even the second. In fact, I think they’ll get the most out of this book after they’ve been working with Rust for a fair while, and starting to feel they’ve got the hang of it. Tim’s book will show them the impressive range and scope of what Rust can do, focusing on the relatively unsung systems programming domain. Those who already have a background in computer science and systems engineering will be delighted by Tim’s clear, charming Rust code, while those who don’t will have their eyes opened to a fascinating new world, and some exciting, if also highly technical, areas of programming.

My own favourite way of writing books is much like Tim’s: to assume no topic is too difficult or obscure for the intelligent reader, and to talk about things I find interesting and hope to interest other people in. Those are the kind of books I enjoy reading, too, so I’m absolutely here for Rust in Action: there’s nothing else like it on the market, and it’ll expand your Rust understanding in a highly enjoyable way.

Zero to Production in Rust

Zero to Production in Rust describes itself as “an opinionated introduction to backend development using Rust,” and that seems very fair. “Opinionated” is the key word here: there are lots of different ways to write any application in Rust, as there are in any language, and this can be a little intimidating, especially at first.

Learning is one thing, but when you just want to get your application up and running quickly, with minimal fuss and without going down too many blind alleys, what you really want is for someone to tell you “Just use tokio,” or “just use actix-web,” or whatever. In other words, it’s really helpful to see a complete and working program written to a professional standard, incorporating all the lessons that an experienced developer will have learned.

That’s exactly what Luca Palmieri presents in Zero to Production in Rust, and he accompanies the code with plenty of clear, vivid, and, yes, opinionated explanations. It’s also nice to see a strong focus on testing, which is something I rather missed in the other books mentioned here.

Something else I appreciate is that he goes to a good deal of trouble to show you, not just the happy path, but what it looks like when things don’t work. For example, if you’ve ever wondered what the mysterious-looking #[tokio::main] attribute actually does, you’re prompted to try removing it and see what the compiler says: “error: main function is not allowed to be async.” Well, well!

Building any application with any language, and any combination of frameworks, can be an exhausting series of choices: every choice you make is important, and will be hard to change later, but you have no idea how to choose well because you don’t know what the trade-offs are.

That’s where a book like Zero to Production in Rust is so valuable: it presents a set of choices that are sensible and pragmatic, and will get you up and running to the point where you can start to investigate other possibilities. You can read a sample of the first three chapters online, or just go ahead and buy the book.

The Secrets of Rust: Tools

 
$29.95
Add To Cart
 

It’s one thing to know Rust, but quite another to actually be able to write useful programs in Rust. For example, how do you start a new project from scratch? How do you decide what the program should behave, and how the user should tell it what to do? And how can you test that stuff?

These are the kind of questions that The Secrets of Rust: Tools tries to answer. It aims to take you beyond the tutorials and toy examples, and bridge the gap between “easy pieces for little fingers” and the complicated world of programs that solve real-world problems.

There’s a strong focus on what the book calls durable software. Durable software is tough and capable: it can cope with diverse and changing environments, it works even when other things are going wrong, and it stays working over long periods of time—many years, or even decades.

Using Rust in the first place helps a lot, of course, but there’s still plenty for us to do as programmers to ensure that our software is durable, usable, performant, and well-designed. The book encourages you to approach software design from the point of view of producing flexible, re-usable open-source components as part of what it calls “the universal library” of Rust crates.

To that end, the book argues for a kind of ruthless simplicity: start with the user’s problem, build a solution in the tiniest possible steps, each step guided by tests. Prioritise a working program, however messy or basic. Once you have that, then keep iterating and polishing it until you can’t find any more ways to make it nicer.

The Secrets of Rust: Tools is currently available in early access, meaning that it’s not yet complete, but when it is, your update will be free. So, if you don’t mind reading a work in progress, it’s a great way to get the book early, and at a hefty discount.

Further reading

If you’re weighing the choice between Rust and Go, or coming to Rust from a Go background, you might be interested in my comparison post, Rust vs Go.

I recently wrote an introduction to error handling in Rust with Option and Result, and there are more tutorials to come, so watch this space (or join my Code Club mailing list).

Happy Rusting!

Will write for food

Will write for food

Shameless green: TDD in Go

Shameless green: TDD in Go

0