ŷ

Jump to ratings and reviews
Rate this book

The Rust Programming Language, 2nd Edition

Rate this book
With over 50,000 copies sold, The Rust Programming Language is the quintessential guide to programming in Rust. Thoroughly updated to Rust’s latest version, this edition is considered the language’s official documentation.

The Rust Programming Language "covers everything you could want to know about the language."—Stack Overflow

Rust has been repeatedly voted "Most Loved Language" on the StackOverflow Developer Survey.


The Rust Programming Language, 2nd Edition is the official guide to Rust 2021: an open source systems programming language that will help you write faster, more reliable software. Rust provides control of low-level details along with high-level ergonomics, allowing you to improve productivity and eliminate the hassle traditionally associated with low-level languages.

Klabnik and Nichols, alumni of the Rust Core Team, share their knowledge to help you get the most out of Rust’sfeatures so that you can create robust and scalable programs. You’ll begin with basics like creating functions, choosing data types, and binding variables, then move on to more advanced concepts, such

Ownership and borrowing, lifetimes, generics, traits, and trait objects to communicate your program’s constraints to the compilerSmart pointers and multithreading, and how ownership interacts with them to enable fearless concurrencyHow to use Cargo, Rust’s built-in package manager, to build, document your code, and manage dependenciesThe best ways to test, handle errors, refactor, and take advantage of expressive pattern matching
In addition to the countless code examples, you’ll find three chapters dedicated to building complete a number-guessing game, a Rust implementation of a command line tool, and a multithreaded server.

527 pages, Kindle Edition

Published February 28, 2023

1,175 people are currently reading
1,792 people want to read

About the author

Steve Klabnik

9books57followers
Steve Klabnik is a prominent software developer and open-source advocate known for his contributions to the Rust programming language. Right now he works as a software engineer at Oxide Computer.
Steve is considered one of the leading experts on Rust, and is widely respected for his knowledge and expertise. He is also a strong advocate for open-source software, believing that it has the power to transform the way we build and use technology.
Through his work, Steve has helped shape the future of programming and technology and has inspired countless developers around the world to embrace new and innovative approaches to software development. He is a sought-after speaker, having given talks at numerous technology conferences and events around the world.

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
989 (58%)
4 stars
557 (33%)
3 stars
125 (7%)
2 stars
8 (<1%)
1 star
1 (<1%)
Displaying 1 - 30 of 178 reviews
Profile Image for James Scholz.
116 reviews3,980 followers
January 17, 2024
took for fkn ever but glad i finished it, certainly cleared up a lot of things for me as a rustacean
Profile Image for Bill de hÓra.
10 reviews44 followers
December 16, 2018
(book also online at ). If you’re looking to learn or explore Rust, this is the book to start with. The book works through the language feature area by feature area, with minimally sized code snippets - the focus is on explanation through the text instead of reams of code. Instead, much of the technical content that the authors use for teaching purposes are compiler error messages, which cleverly leverages one of the language’s best features, and one programmers will spend a lot of time with in practice (Rust has quite clear compiler messages).

Overall the content is well laid out with minimal forward references. There’s a lot of emphasis given to the concept of of ownership, borrowing and lifecycles, which are the most novel aspects relative to other languages. The sections on testing, generics/traits, pattern matching, and object oriented programming, are particularly strong. I would have liked to have seen function pointers covered earlier in the initial section on functional language features, and extended coverage on references, but these are minor enough, and what’s there is enough to get the gist.

Every now and then you come across a software book that’s enjoyable for its own sake, The Rust Programming Language is one of those books - not just an excellent introductory book on Rust but an exemplar of technical writing.
Profile Image for Nick Black.
Author2 books865 followers
October 21, 2020
as i postpended to my review of , after twenty years of writing C and C++ professionally and ten years' amateur work prior, i have adopted Rust, and thus the first language i've found that is all of (1) generally applicable to my kind of systems+numerical programming, (2) superior to C, and (3) superior to C++ (i consider the two to be only weakly ordered). i expect to use it for the next thirty years or so. this is a solid introduction to Rust, but lacks the sublime. experienced programmers needn't read it to effectively use Rust, though it certainly won't hurt. i was hoping for more. Stroustrup's is full of wisdom that transcends a language reference; K&&R is too short to carry much beyond one. tRPL spends too much time giving pithy pedestrian advice, and not enough text exhaustively covering the language and its runtime. its lack of greatness, however, is due to rising above neither reference nor speller; there is nothing here to leave a master with a piquant memory.

with that said, baller move making it freely available.
Profile Image for Jindřich Mynarz.
120 reviews17 followers
February 3, 2019
I have no plans to write Rust, yet I appreciated the book. Its clarity of writing is exceptional and the Rust's concepts are introduced in an instructive way. Even as a person who develops in more declarative, higher-level, dynamic, and garbage-collected languages I found the book useful as its explains many of the underlying low-level aspects of computing, such as reference counting.

Rust follows the principle of "zero-cost abstraction", where the cost means performance cost, which is obviously achieved at some cognitive cost to the developer. Even though Rust tries to limit the cognitive overhead, often I found myself thinking there's way too much syntax in it. However, I think people coming to Rust understand and accept that with its great power comes some cognitive tax.
Profile Image for Sebastian Gebski.
1,148 reviews1,254 followers
November 30, 2018
*** Important. This is the review of the 2nd Edition - a complete re-write of the original book ***

Disclaimer #1: You can read the book here: - for free. I've reviewed the Kindle version by NoStarchPress.
Disclaimer #2: I was familiar with Rust before reading the book, so for me it was just a great opportunity to review the syntax, idioms, etc.

This book "implements" my favorite approach to teaching programming languages - it's not a dry review of syntax, but also it's not a selective description of particular statements based on cryptic, pseudo-real programs. What is it then? A healthy compromise, with awesome examples. The start is smooth (but you should have a prior experience with some programming language) & it's aimed to set you up properly, not to make you an expert. What I really liked was the description of the most tricky aspects of Rust: ownership & lifetimes - truly decent job! The worst chapter is probably the concurrency one - felt overloaded & a bit unclear - in terms what's consider as an idiomatic approach in Rust.

But still - if you're about to start your journey with Rust, this book is a great choice.
Profile Image for Arun.
207 reviews64 followers
August 12, 2021
I have been using rust at work comfortably before reading this book and knew everything talked about in the book either from trial and error or from reading blogs/open source code etc. But completing this book is like a rite of passage for rustaceans so I decided to give it a shot. If you are already doing s/w eng. for a while, it doesn't shock you with grandeur wisdom but admittedly the prose style is beautiful that one can read it like a well written novel and consider that time well spent.
Profile Image for Greg Stoll.
349 reviews13 followers
July 4, 2021
An excellent way to learn Rust, with some fairly meaty topics to boot. Every time I read through the book again I learn something!
Profile Image for Sebastian Gebski.
1,148 reviews1,254 followers
November 16, 2019
The best Rust reference book I know.
I've re-read the latest version (the one that covers Rust 2018) & it's still stellar - easy to understand (even more tricky topics - like lifetimes or traits), concise, illustrated with good code samples.
It's already a bit outdated (async-await support is not present), but still - it's the most up-to-date book resource available.

What I didn't like? NoStarch has provided no option to upgrade the previous edition. And they didn't answer my inquiries. I've read 2018 ed. only because I had a "free" access to it on the O'Reilly platform.
Profile Image for Utsob Roy.
Author2 books76 followers
September 18, 2021
তো, আম� তো কোনোকালে� সিস্টে� প্রোগ্রামা� না� ইউজা�-ফেসি� জিনিসপত্� নিয়েই আমার কারবার� সিম্পল� মন চায় বল� এট� ওট� ঘেঁট� দেখি� আগ� একবা� রাস্� অ্যাপ্রো� করেছিলাম, তখ� ভালো লাগেনাই। এই বইটা পড়ে বর� ভালো লেগেছে�

অধুনাকাল� জনপ্রিয় দুটো ল্যাঙ্গুয়েজ আমার� ভালো লেগেছে� গো- মিনিম্যালিস্� অ্যাপ্রো� আর কনকারেন্সি� জন্য, ডার্�-সিনট্যাক্সের জন্য�

তো, রাস্� ভালো লেগেছে কয়েকট� কারনে। ম্যা� সিনট্যাক্স, সেফট� ফিচারস, ভালো কম্পাইলা�, আর বিল্� সিস্টেম। তাছাড়� গো-এর মত ওওপি-এর কম্পোজিশ�-বেজড অ্যাপ্রোচ।

বইটা রেকমেন্ডেড কেনন� লেখা স্বচ্ছ�, ভালোভাবে অনেককিছু এক্সপ্লেইন কর� আছে।
Profile Image for Lucas.
159 reviews32 followers
April 28, 2021
Meu primeiro contato com rust. É uma linguagem fantástica. É impressionante a consistência lógica de tudo. Mas, ao menos para mim, é a linguagem mais difícil que tive contato até aqui. Isso não deve surpreender. Até hoje trabalhei apenas com linguagens de alto nível e nunca precisei me preocupar se um objeto que estava manipulando ficava no stack ou no heap. O estranhamento é natural, portanto.

Certamente seu estranhamento será menor que o meu se você é um programador de C.

Se você nunca programou em outra linguagem, minha sugestão é começar por uma de alto nível.

Apesar da dificuldade, que também se relaciona com a necessidade de aprender novos conceitos (se você vem de python: struct, enum; se você vem de qualquer outra linguagem: borrowing), o livro é extremamente bem escrito com leitura super acessível. Eu aprendi muito, mas vou precisar voltar de tempos em tempos em cada capítulo que li.

Se você quer aprender rust, eu não vejo outra forma que não lendo esse livro. Não conheço nenhum curso online de boa qualidade e "meter a cara" na linguagem, como eu fiz, vai causar muita frustração, posso garantir.
Profile Image for Ricardo Signes.
69 reviews6 followers
December 16, 2023
On a previous read, I gave this "just good". I think I may still feel the same way, but now I feel like achieving "just good" with this complex topic is a good job. I also think it helped that I have (a very small amount) more practical experience with the language, now, that made it possible to finish the whole book without getting stuck in a place where things had become too speculative.

Chapter 20, the "final project", has the reader build a multi-threaded web server. It's a complete toy, but it's also fifty lines to show how much the reader has learned, and it really does perform safe multi-threaded network request service. It was a really good final chapter.

This is definitely not the only Rust book to read to learn Rust, but it was a good one.
Profile Image for Meysam.
57 reviews
April 4, 2023
"The Book," as they call it in the Rust community, is a good starter for anyone who wants to grasp all the fundamentals of the language. Still, at the same time, I found the examples and snippets very hard to follow as they tend not to be a complete reproducible example but rather a piece-by-piece snippet that you'd have to manually copy & paste to your editor to get a working code.

Anyone who has already read through the documents of probably knows what I'm talking about; you will get a complete reproducible example at every step of the way. It's not the same with Rust's bible book.

Overall, I found the book very entertaining to follow and not at all boring. The book is a must-read to start your way into the language, but never enough to become a real "Rustacean" :).

All in all, starting my software engineering journey from a compiled language (C++) and then inclining towards a dynamically typed language (Python), I tend to think that world of software needs more robustness and reliability through the safeguards of compiler errors and strict static typing. Any software worth its name will need this much rigidness built-in as a first-class citizen if it wants to live for decades.
Profile Image for Vlad Ardelean.
155 reviews33 followers
August 22, 2023
Good intro to rust. Free book online!

Rust is very innovative with both its lack of a garbage collector and memory safety.

But indeed, if only one variable can be the "owner" of a value, implementing stuff like graphs and doubly linked lists becomes tricky.

The language offers work-arounds for these cases, that are still memory safe, like these:
* Rc -> a reference counting kind of construct, that allows multiple owners
* Arc -> like Rc, but thread safe
* Cell -> allows mutation of immutable variables residing on the stack
* RefCell -> like Cell, but for stuff that lives on the heap
* Box -> a wrapper that allows defining recursive data structures
* Mutex -> because Arc only makes the reference counting safe, the mutex allows safe concurrent manipulation of data

...probably rust has a lot more primitives, but those were in the book

Also the compiler is very helpful to newbies. There was one case where it confused me, and I spent a few hours trying to figure out that one can't send immutable pointers to other threads easily (because those particular immutable pointers didn't guarantee that they'll live long enough).
Profile Image for Charlie.
2 reviews
September 16, 2020
a must-read introduction to rust. this book contains concise yet thorough explanations of features unique to rust. the writing is excellent and the complexity of the examples is "just right". and it's freely available!

i'd say it does assume both prior coding experience and a little computer architecture knowledge (e.g. stack vs. heap, pointers, etc.), so a complete beginner might struggle to follow. that said, rust itself is probably not the ideal first programming language.

learning rust definitely will change how you think about programs. and this book is the perfect way to get started
Profile Image for Jelle van Geel.
2 reviews
May 3, 2024
Compared to other technical books, this one really stands out. The concepts were easy to grasp and the difficulty progresses nicely throughout the book.

I started working with Rust a while ago, and the information in this book helped me out a lot. By the time I got to chapter 19 about advanced concepts I could apply them right away; I wrote a procedural macro so I could pass in structs as generic types and enforce the use of certain fields or supply a default value when it's absent.

Aside from that it didn't really feel like other technical books I've read before. It felt more light hearted and to the point. It has examples that are easy to understand and it's about one of the most interesting programming languages out there! Recommend.
Profile Image for Matt.
Author1 book24 followers
November 13, 2019
I thought this was a great way to get into Rust. The examples are good and the explanations are clear.
Profile Image for David.
91 reviews5 followers
February 9, 2020
Pretty typical programming language intro book. It’s well written and thorough � enough to be a useful reference later on.
8 reviews
October 3, 2021
Just what I would expect from a book of this type. Very well written with lots of useful snippets that help with grasping the concepts.
148 reviews
December 30, 2023
Good technical introduction and reference. Many examples, covers a lot of ground.
9 reviews
January 16, 2025
Good programming book
This entire review has been hidden because of spoilers.
Profile Image for Karton.
8 reviews
November 18, 2023
I learned more than in school but boi is it sometimes hard to process
1 review
March 26, 2020
Very approachable! I also recommend the authors' 'Rust in Motion' course before reading the book
Profile Image for Dana Larose.
410 reviews15 followers
Read
January 30, 2020
A very good introduction to Rust, a programming language which, after reading the book, I am pretty sure I am too dumb to ever be any good at. The explanations were clear but several concepts I still don't quite get. Lifetimes, for instance, and Rust's implementations of closures. But I think that's me being thick-headed not the book being unclear.

I feel like the current version (as of January 2020) is a little bit out of date because the Rust community is making a big deal out of async/await being added to the language (I believe in the fall) and the book currently doesn't speak of it at all.

But I'm committed to trying at least one decent-sized project in Rust this year. I'll come back and give a star rating to the book depending on if the project is a success or a failure :P
Profile Image for Kai.
243 reviews23 followers
June 9, 2023
If you've installed Rust using the official `rustup` installer, The Rust Programming Language is included as part of the package. The Second Edition was written by Steve Klabnik and Carol Nichols and complemented by members of the Rust Community. Given this background it won't surprise that the document reads like advertisement that praises the many merits of the Rust Programming Language.

I have to admit, I was quickly turned into a believer. Everything appears to be very well thought-through and well-rounded. I cannot judge whether the language is as secure as its maintainers claim it is, even if many professionals seem to think so. But what the introductory book does is to convincingly explain the pitfalls that the design principle try to avoid.

The motivation for the particularities at hand are occasionally given with reference to perceived (and often widely acknowledged) problems of other popular language. The dangers of buffer-overruns are a case in point:
"In C, attempting to read beyond the end of a data structure is undefined behavior. You might get whatever is at the location in memory that would correspond to that element in the data structure, even though the memory doesn’t belong to that structure."

Another common issue of languages with a garbage collector or manual memory allocation are double free errors: "Freeing memory twice can lead to memory corruption, which can potentially lead to security vulnerabilities." Rust's most defining feature, its ownership system, overcomes this issue. Teaching the ideas of ownership, references, and borrowing are a main concern in the early chapters. Noteworthy also is that Rust attempts to .

In other cases, Rust's language design is motivated by the belief that bugs are best prevented early � even if this will be frustrating for beginners. Here is one example:
"It’s important that we get compile-time errors when we attempt to change a value that’s designated as immutable because this very situation can lead to bugs. If one part of our code operates on the assumption that a value will never change and another part of our code changes that value, it’s possible that the first part of the code won’t do what it was designed to do. The cause of this kind of bug can be difficult to track down after the fact, especially when the second piece of code changes the value only sometimes. The Rust compiler guarantees that when you state that a value won’t change, it really won’t change, so you don’t have to keep track of it yourself. Your code is thus easier to reason through."
The requirements of the type system belong in this context, too, even though there are some comfort features like type inference.

If you are an absolute beginner, worries about performance probably won't be too readily on your mind. Nonetheless, the writers address questions of relevance to a wider audience. For instance, we learn early on that "Rust will never automatically create 'deep' copies of your data [i.e. the same data is stored at different locations of the heap]. Therefore, any automatic copying can be assumed to be inexpensive in terms of runtime performance."

In the chapter on Rust programming in accordance with a functional paradigma the authors express the language's strive for zero-cost abstractions. The reader is introduced to iterators whose purpose is to abstract away from some non-substantial details when going through the elements of data structures. In this way we avoid boilerplate and thereby highlight what is of actual relevance. But it's natural to wonder whether the abstraction comes with a price of performance when compared with the more lower-level loops that other language use for this purpose. Surprisingly, benchmarks are cited that appear to be solid evidence that this is not actually the case.

The goal of exposing bugs early on can lead to puzzling results, especially when something isn't as simple as you thought it would be. Strings are the prime example. It's not only that there are two types of strings, collections (vectors of bytes) and string slices (that include string literals). If you come from a different modern language you'll almost certainly be nonplussed to find that the creators of Rust decided against string indexing.

At first sight this seems unnecessarily cumbersome. The first character of the string "hello" is clearly 'h', so why wouldn't "hello"[0] be 'h'? I was amazed by the reasoning we are confronted with. Most importantly, and contrary to what you might expect, the characters in the popular UTF-8 encoding are not all one byte long. The Russian "Здравствуйте", for instance, takes up 24 bytes of space. Moreover, there are diacritics that combine with proper letters to form single characters; however, they take memory space of their own. So, when counting the length of a string we have to think of grapheme clusters. To screen these details from the user may feel convenient � but it does lead to problems and bugs when dealing with the writing systems of many natural languages. Rust takes this seriously by counting string length in terms of bytes rather than in terms of proper characters � and given the argument the reader will be convinced that this is the way to go.

To me reading other introductions to programming was often a frustating experience. I have this directory, `Projects` (`Repositories`, whatever), and within this directory I have a subdirectory named after the application I'm developing. But now what, where would you put your files? You often come across names like `src`, `bin`, `lib`, but how should you structure your projects?

With Cargo it became increasingly difficult for me to separate my excitement about the quality-of-life improvements that it promises from how I felt about the book that is telling me about it. "There’s a place for everything, and everything is in its place." I'm an order-loving librarian at heart, so hooray for structure and system! I felt virtually elated when reading the numerous chapters on the built-in package manager.

In this context I was impressed by how clearly the book explains the concepts of modules and submodules, crates (library and binary), crate roots, packages, workspaces, paths, and how they are connected with each other and with ideas like scope and privacy. Additional structure comes from separating modules onto different files, a practice also explained in detail. It even provides you with the Modules Cheat Sheet, "a list of rules for easy reference when you’re organizing your code in the future".

Throughout more advanced concepts are used, but always with reference to the chapters where they are elaborated on in detail. Some topics are actually quite advanced and subtle. The introduction warns us about common misconceptions and mistakes that new Rustaceans (as the community calls its members) tend to make. This brings me to what I easily liked the most about the introduction, the exceptionally illuminating examples.

At first I was suprised to find that there are more examples that won't compile than ones that actually do work. I think what makes people quit programming is the frustrating experience of an endless series of errors. Even if you are able to fix things, often your program still doesn't work. Rust has a reputation of being particularly unforgiving. The book demonstrates heart and empathy when it verbalizes what it is that learners are getting wrong or why they make the mistakes they are making. I think this is a very important skill that many teachers completely lack.

So we often go through many iterations of the same program. If you write code with no regard for potential complications of course you end up with a result that is more simple and more concerned with the problem-solving at hand. I think this is one reason why it's often good to first discuss a listing that is not actually compiling. Sometimes more advanced techniques are necessary to make things work; didactically, it's more motivating to think through a version you fully understand. You get a sense of this being code that would work, if only you had known better. Incidentally, the error messages are so amazingly descriptive, they point you in the right direction even if you've never heard of the terms before.

Of course even if your code compiles, there is often still room for improvement. I was absolutely blown away about the refactoring in Chapter 12. Our `minigrep` is quickly established, but it was seriously awesome to see in how many ways it could be improved. For instance, it is explained how the main function should interact with library crates; for this reason we refactor our functions out of the main file where they were initially defined. In the past I often wondered about the best practice to define an argument parser; here I was amazed by the interplay of functions and how to use a Config struct to make clear the relationship between the configuration variables. New functionality is developed following a test-driven approach. Later loops are replaced by iterators. It's the kind of real-world advice that I think makes you more confident in the code you write.

Overall, The Rust Programming Language is easily among the best programming introductions I've read. It's hands-on and you won't be bogged down in technical details, yet the level of complexity and advancement are steadily improved to give you a solid understanding of how people in the real world write code in Rust. No book will make you an experienced programmer in any language � but the Rust Community gives you a very solid foundation.

Rating: 5/5
8 reviews
June 18, 2022
Very good and easy read! I wish it had more coding exercises so I would have had more opportunities to practice. Copying the code from the examples and then running it gets pretty boring.
Displaying 1 - 30 of 178 reviews

Can't find what you're looking for?

Get help and learn more about the design.