Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Steve Klabnik, Carol Nichols

Rating No ratings yet

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's features 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 as: -Ownership and borrowing, lifetimes, generics, traits, and trait objects to communicate your program's constraints to the compiler -Smart pointers and multi threading, and how ownership interacts with them to enable fearless concurrency -How to use Cargo, Rust's built-in package manager, to build, document your code, and manage dependencies -The 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 projects: a number-guessing game, a Rust implementation of a command line tool, and a multi threaded server.

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
# The Rust Programming Language, 2nd Edition ## 【One-Line Pitch】 The official, comprehensive introduction to Rust 2021 from two Rust Core Team alumni, teaching you how to write fast, reliable systems software with memory safety guarantees and modern ergonomics. Essential reading for programmers coming from C/C++, Python, or JavaScript who want to master ownership, concurrency, and building production-grade applications. ## 【Book Arc】 - **Opening (~0%–11%)**: Getting started with Rust — installation via rustup, writing your first "Hello, world!" program, and understanding Cargo as both build system and package manager. Introduces fundamental syntax: variables, data types, functions, and control flow, culminating in a number-guessing game project. - **Early (~11%–26%)**: The heart of Rust — ownership, borrowing, references, and slices (Chapter 4), then structs, enums, and pattern matching. Covers module systems for organizing growing projects and common collections like vectors and strings. Includes Cargo's release profiles and publishing crates to crates.io. - **Middle (~26%–52%)**: Error handling, generics, traits, and lifetimes — the abstractions that let you communicate constraints to the compiler. Introduces testing, closures, iterators, and smart pointers (Box, Rc, RefCell), plus building a command-line tool (grep implementation) as a practical project. - **Late (~52%–81%)**: Concurrency and fearless multithreading, object-oriented programming patterns in Rust (trait objects, the state pattern), and a deep reference on patterns and pattern matching. Covers advanced features: unsafe Rust, advanced traits, type aliases, function pointers, and macros. - **Ending (~81%–100%)**: Final project — building a multithreaded web server from scratch. Appendices provide reference material on keywords, operators, derivable traits, development tools, and Rust editions. Installation troubleshooting and backward-compatibility guarantees are also covered. ## 【Key Takeaways】 - **Ownership is Rust's defining concept** (Early): Every value has a single owner; when the owner goes out of scope, the value is dropped. This eliminates memory leaks and data races at compile time — the core trade-off that makes Rust both safe and fast. - **Borrowing and references enable safe sharing** (Early): The rules — you can have either one mutable reference or many immutable references, and references must always be valid — prevent dangling pointers and data races without runtime overhead. - **Enums and pattern matching replace null and exceptions** (Early): `Option<T>` forces you to handle the absence of a value explicitly, and `match` expressions are exhaustive, meaning the compiler checks that you've handled every case. - **Traits and generics provide abstraction without runtime cost** (Middle): Traits define shared behavior across types, and generics with monomorphization mean you get code reuse without sacrificing performance — a key advantage over dynamic dispatch in other languages. - **Cargo is more than a package manager** (Early): It handles building, testing, documenting, and dependency management. Publishing to crates.io follows a straightforward workflow, and release profiles let you optimize for speed or binary size. - **Fearless concurrency comes from the type system** (Late): Ownership rules extend to threads — `Send` and `Sync` traits ensure you can't accidentally share data across threads unsafely. The compiler catches race conditions before runtime. - **Smart pointers extend ownership semantics** (Middle): `Box<T>`, `Rc<T>`, and `RefCell<T>` provide different ownership models (single owner, shared ownership, interior mutability), each with specific trade-offs between flexibility and safety guarantees. - **Unsafe Rust is a deliberate, scoped escape hatch** (Late): The `unsafe` keyword lets you dereference raw pointers, call unsafe functions, and access mutable statics — but only within clearly marked blocks, preserving safety guarantees elsewhere. ## 【Reading Tips】 - **Deep-read Chapters 4–6** (ownership, structs, enums): These are the conceptual foundation of everything else. Don't rush; work through the memory diagrams and examples carefully, as they explain *why* Rust behaves the way it does. - **Skim the project chapters initially** (number-guessing game, grep tool, web server): Return to them after finishing the surrounding chapters — they consolidate concepts but are more valuable once you've seen the underlying ideas. - **Treat Chapter 19 (Advanced Features) as a reference**: Unsafe Rust, macros, and advanced types are important but not needed for everyday programming. Read the sections you need when you need them. - **Use the appendices as a cheat sheet**: Keywords, operators, and derivable traits are organized for quick lookup — keep them bookmarked rather than memorizing. - **Expect to reread**: The book explicitly acknowledges there's "no wrong way to read it." If a concept confuses you, jumping back to earlier chapters is expected and encouraged. ## 【Coverage Limits】 This guide synthesizes the book's structure and key concepts from the table of contents, chapter summaries, and introductory material. Detailed code examples, specific syntax explanations, and the full text of the three project chapters are not covered in this guide — the excerpts primarily capture chapter organization and conceptual overviews rather than complete implementations. ##
Excerpt 1
readed server. The Rust Programming Language, 2nd Edition The Rust Programming Language, 2nd Edition Contents In Detail Title Page Copyright About the Author...
View in text
Excerpt 2
rsion of an Existing Crate Deprecating Versions from Crates.
View in text
Excerpt 3
Macros and Functions Declarative Macros with macro_rules!
View in text
Excerpt 4
t prints Hello, world! Listing 1-2: Contents of Cargo.
View in text
Excerpt 5
side the front_of_house module in src/front_of_house.
View in text
Excerpt 6
utomatically by cargo new Listing 11-2: The output from running the automatically generated test Listing 11-3: Adding a second test that will fail because we...
View in text
Excerpt 7
y. Nichols has also organized the Rust Belt Rust Conference. About the Technical Reviewer JT is a Rust core team member and the co-creator of the Rust error...
View in text
Excerpt 8
Windows, a file containing debugging information with the .pdb extension. From here, you run the main or main.exe file, like this: $ ./main # or .\main.exe o...
View in text
Tags
AI categories
Programming LanguageBackendTechnology
ISBN: 1593278519
Publisher: No Starch Press
Publish Year: 2023
Language: English
Pages: 861
File Format: EPUB
File Size: 2.4 MB