The Rust Programming Language, 2nd Edition

Capa
No Starch Press, 28 de fev. de 2023 - 560 páginas
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’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 multithreading, 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 multithreaded server.
 

Páginas selecionadas

Conteúdo

Getting Started
1
Hello Cargo
7
Programming a Guessing Game
13
Comparing the Guess to the Secret Number
23
Summary
30
Common Programming Concepts
31
Data Types
36
Functions
43
Developing the Librarys Functionality with TestDriven Development
259
Working with Environment Variables
265
Summary
272
Functional Language Features Iterators and Closures
273
Processing a Series of Items with Iterators
284
Loops vs Iterators
293
More About Cargo and Crates io
295
Smart Pointers
315

Comments
49
Summary
58
Understanding Ownership
59
References and Borrowing
71
Using Structs to Structure Related Data
85
An Example Program Using Structs
91
Method Syntax
97
Enums and Pattern Matching
103
The match Control Flow Construct
110
Concise Control Flow with if let
116
Managing Growing Projects with Packages Crates and Modules
119
Defining Modules to Control Scope and Privacy
123
Bringing Paths into Scope with the use Keyword
132
Summary
140
Common Collections
141
Storing UTF8 Encoded Text with Strings
147
Summary
159
Error Handling
161
Recoverable Errors with Result
165
To panic or Not to panic
175
Generic Types Traits and Lifetimes
181
Defining Shared Behavior
192
Validating References with Lifetimes
201
Generic Type Parameters Trait Bounds and Lifetimes Together
213
Writing Automated Tests
215
Test Organization
236
Summary
242
An IO Project Building a Command Line Program
243
Refactoring to Improve Modularity and Error Handling
248
Treating Smart Pointers Like Regular References with Deref
321
Running Code on Cleanup with the Drop Trait
327
RefCellT and the Interior Mutability Pattern
334
Reference Cycles Can Leak Memory
343
Summary
351
Fearless Concurrency
353
Using Message Passing to Transfer Data Between Threads
361
SharedState Concurrency
367
Extensible Concurrency with the Send and Sync Traits
373
ObjectOriented Programming Features
375
Using Trait Objects That Allow for Values of Different Types
379
Summary
396
Patterns and Matching
397
Whether a Pattern Might Fail to Match
403
Summary
418
Advanced Features
419
Advanced Traits
430
Advanced Types
440
Advanced Functions and Closures
446
Macros
449
Final Project Building a Multithreaded Web Server
459
Turning Our SingleThreaded Server into a Multithreaded Server
471
Graceful Shutdown and Cleanup
487
Summary
493
Keywords
495
C
507
Useful Development Tools
511
Direitos autorais

Outras edições - Ver todos

Termos e frases comuns

Sobre o autor (2023)

Carol Nichols is a member of the Rust Community Team and a former member of the Rust Core Team. Also active in the Ruby community, she was a key organizer of the Steel City Ruby Conference 2012-2014.

Steve Klabnik is the Community Team Leader for the Rust team at Mozilla, in charge of official Rust community documentation, as well as a trusted Rust community advocate. Klabnik is a frequent speaker at conferences and one of the world's most prolific contributors to Rails projects.

Informações bibliográficas