The Leanpub 60 Day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms...
how the compiler works
About the Book
Most Rust books teach you the language — ownership, traits, the borrow checker, how to structure a crate. Rust Deep Dive assumes you've already been through that. It picks up where those books stop and asks a different question: what does rustc actually do with the code you write?
A generic function isn't one function — it's N functions, one per concrete type, each compiled and optimized separately. Option<&T> isn't a tagged union with wasted space — the compiler notices that references are never null and reuses the invalid bit pattern, so the Option costs nothing. An async fn isn't sugar over a callback — it's a state machine, generated by the compiler, with a field for every value that has to survive across an .await point. None of this is visible in the source code. All of it explains why the code behaves, compiles, and performs the way it does.
Each chapter takes one piece of the compiler's behavior and goes deep: what internal representation it uses, what tool output (--emit=mir, --emit=llvm-ir, cargo expand, cargo bloat) actually shows you, and what tradeoffs the compiler is making on your behalf. Across 35 chapters and eleven parts, the book follows the compiler's own pipeline and then radiates out into the corners that pipeline touches:
unsafe takes over what the compiler can no longer checkrepr variants, niche optimization, smart pointers, and the allocatorno_std, string representation, collections, and iteratorsBy the end, the goal isn't trivia about rustc internals. It's a mental model precise enough that borrow checker errors stop feeling arbitrary, performance regressions stop feeling mysterious, and reaching for unsafe, Pin, or a #[repr] attribute feels like a deliberate choice rather than a leap of faith.
This book is for developers who already write Rust — comfortably, not necessarily expertly — and have started asking why. You'll get the most out of it if you:
unsafe blocks, even if you don't write them oftenYou don't need to be a compiler engineer to read this book, and you won't come out of it one — but you'll never look at a cargo build the same way again.
+, and where
About the Author
Click the buttons to get the free sample in PDF or EPUB, or read the sample online here
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms...
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.
Learn more about writing on Leanpub
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!
Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.
Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.