]> git.proxmox.com Git - rustc.git/blame - src/doc/book/nostarch/introduction.md
New upstream version 1.64.0+dfsg1
[rustc.git] / src / doc / book / nostarch / introduction.md
CommitLineData
923072b8
FG
1<!-- DO NOT EDIT THIS FILE.
2
3This file is periodically generated from the content in the `/src/`
4directory, so all fixes need to be made in `/src/`.
5-->
6
7[TOC]
8
9# Introduction
10
11Welcome to *The Rust Programming Language*, an introductory book about Rust.
12The Rust programming language helps you write faster, more reliable software.
13High-level ergonomics and low-level control are often at odds in programming
14language design; Rust challenges that conflict. Through balancing powerful
15technical capacity and a great developer experience, Rust gives you the option
16to control low-level details (such as memory usage) without all the hassle
17traditionally associated with such control.
18
19## Who Rust Is For
20
21Rust is ideal for many people for a variety of reasons. Let’s look at a few of
22the most important groups.
23
24### Teams of Developers
25
26Rust is proving to be a productive tool for collaborating among large teams of
27developers with varying levels of systems programming knowledge. Low-level code
064997fb
FG
28is prone to various subtle bugs, which in most other languages can be caught
29only through extensive testing and careful code review by experienced
923072b8
FG
30developers. In Rust, the compiler plays a gatekeeper role by refusing to
31compile code with these elusive bugs, including concurrency bugs. By working
32alongside the compiler, the team can spend their time focusing on the program’s
33logic rather than chasing down bugs.
34
35Rust also brings contemporary developer tools to the systems programming world:
36
37* Cargo, the included dependency manager and build tool, makes adding,
38 compiling, and managing dependencies painless and consistent across the Rust
39 ecosystem.
064997fb
FG
40* The Rustfmt formatting tool ensures a consistent coding style across
41 developers.
923072b8
FG
42* The Rust Language Server powers Integrated Development Environment (IDE)
43 integration for code completion and inline error messages.
44
45By using these and other tools in the Rust ecosystem, developers can be
46productive while writing systems-level code.
47
48### Students
49
50Rust is for students and those who are interested in learning about systems
51concepts. Using Rust, many people have learned about topics like operating
52systems development. The community is very welcoming and happy to answer
53student questions. Through efforts such as this book, the Rust teams want to
54make systems concepts more accessible to more people, especially those new to
55programming.
56
57### Companies
58
59Hundreds of companies, large and small, use Rust in production for a variety of
064997fb
FG
60tasks, including command line tools, web services, DevOps tooling, embedded
61devices, audio and video analysis and transcoding, cryptocurrencies,
923072b8
FG
62bioinformatics, search engines, Internet of Things applications, machine
63learning, and even major parts of the Firefox web browser.
64
064997fb
FG
65<!-- with Rust adopted in a lot of really recognizable names, is it worth
66namedropping some companies that use Rust significantly? /LC -->
67<!-- No, I don't want to show favoritism, and there are lots of politics around
68the big companies using Rust that I don't want to get into. I would also worry
69about the list getting dated. /Carol -->
70
923072b8
FG
71### Open Source Developers
72
73Rust is for people who want to build the Rust programming language, community,
74developer tools, and libraries. We’d love to have you contribute to the Rust
75language.
76
77### People Who Value Speed and Stability
78
79Rust is for people who crave speed and stability in a language. By speed, we
064997fb
FG
80mean both how quickly Rust code can run and the speed at which Rust lets you
81write programs. The Rust compiler’s checks ensure stability through feature
82additions and refactoring. This is in contrast to the brittle legacy code in
83languages without these checks, which developers are often afraid to modify. By
84striving for zero-cost abstractions, higher-level features that compile to
85lower-level code as fast as code written manually, Rust endeavors to make safe
86code be fast code as well.
923072b8
FG
87
88The Rust language hopes to support many other users as well; those mentioned
89here are merely some of the biggest stakeholders. Overall, Rust’s greatest
90ambition is to eliminate the trade-offs that programmers have accepted for
91decades by providing safety *and* productivity, speed *and* ergonomics. Give
92Rust a try and see if its choices work for you.
93
94## Who This Book Is For
95
96This book assumes that you’ve written code in another programming language but
97doesn’t make any assumptions about which one. We’ve tried to make the material
98broadly accessible to those from a wide variety of programming backgrounds. We
99don’t spend a lot of time talking about what programming *is* or how to think
100about it. If you’re entirely new to programming, you would be better served by
101reading a book that specifically provides an introduction to programming.
102
103## How to Use This Book
104
105In general, this book assumes that you’re reading it in sequence from front to
106back. Later chapters build on concepts in earlier chapters, and earlier
064997fb
FG
107chapters might not delve into details on a particular topic but will revisit
108the topic in a later chapter.
923072b8
FG
109
110You’ll find two kinds of chapters in this book: concept chapters and project
111chapters. In concept chapters, you’ll learn about an aspect of Rust. In project
112chapters, we’ll build small programs together, applying what you’ve learned so
113far. Chapters 2, 12, and 20 are project chapters; the rest are concept chapters.
114
115Chapter 1 explains how to install Rust, how to write a “Hello, world!” program,
116and how to use Cargo, Rust’s package manager and build tool. Chapter 2 is a
064997fb
FG
117hands-on introduction to writing a program in Rust, having you build up a
118number guessing game. Here we cover concepts at a high level, and later
119chapters will provide additional detail. If you want to get your hands dirty
120right away, Chapter 2 is the place for that. Chapter 3 covers Rust features
121that are similar to those of other programming languages, and in Chapter 4
122you'll learn about Rust’s ownership system. If you’re a particularly meticulous
123learner who prefers to learn every detail before moving on to the next, you
124might want to skip Chapter 2 and go straight to Chapter 3, returning to Chapter
1252 when you’d like to work on a project applying the details you’ve learned.
923072b8
FG
126
127Chapter 5 discusses structs and methods, and Chapter 6 covers enums, `match`
128expressions, and the `if let` control flow construct. You’ll use structs and
129enums to make custom types in Rust.
130
131In Chapter 7, you’ll learn about Rust’s module system and about privacy rules
132for organizing your code and its public Application Programming Interface
133(API). Chapter 8 discusses some common collection data structures that the
134standard library provides, such as vectors, strings, and hash maps. Chapter 9
135explores Rust’s error-handling philosophy and techniques.
136
137Chapter 10 digs into generics, traits, and lifetimes, which give you the power
138to define code that applies to multiple types. Chapter 11 is all about testing,
139which even with Rust’s safety guarantees is necessary to ensure your program’s
140logic is correct. In Chapter 12, we’ll build our own implementation of a subset
141of functionality from the `grep` command line tool that searches for text
142within files. For this, we’ll use many of the concepts we discussed in the
143previous chapters.
144
145Chapter 13 explores closures and iterators: features of Rust that come from
146functional programming languages. In Chapter 14, we’ll examine Cargo in more
147depth and talk about best practices for sharing your libraries with others.
148Chapter 15 discusses smart pointers that the standard library provides and the
149traits that enable their functionality.
150
151In Chapter 16, we’ll walk through different models of concurrent programming
152and talk about how Rust helps you to program in multiple threads fearlessly.
153Chapter 17 looks at how Rust idioms compare to object-oriented programming
154principles you might be familiar with.
155
156Chapter 18 is a reference on patterns and pattern matching, which are powerful
157ways of expressing ideas throughout Rust programs. Chapter 19 contains a
158smorgasbord of advanced topics of interest, including unsafe Rust, macros, and
159more about lifetimes, traits, types, functions, and closures.
160
161In Chapter 20, we’ll complete a project in which we’ll implement a low-level
162multithreaded web server!
163
164Finally, some appendices contain useful information about the language in a
165more reference-like format. Appendix A covers Rust’s keywords, Appendix B
166covers Rust’s operators and symbols, Appendix C covers derivable traits
167provided by the standard library, Appendix D covers some useful development
168tools, and Appendix E explains Rust editions.
169
170There is no wrong way to read this book: if you want to skip ahead, go for it!
171You might have to jump back to earlier chapters if you experience any
172confusion. But do whatever works for you.
173
174An important part of the process of learning Rust is learning how to read the
175error messages the compiler displays: these will guide you toward working code.
176As such, we’ll provide many examples that don’t compile along with the error
177message the compiler will show you in each situation. Know that if you enter
178and run a random example, it may not compile! Make sure you read the
179surrounding text to see whether the example you’re trying to run is meant to
180error. In most situations, we’ll lead you to the correct version of any code
181that doesn’t compile.
182
183## Resources and How to Contribute to This Book
184
185This book is open source. If you find an error, please don't hesitate to file
186an issue or send a pull request on GitHub at
187*https://github.com/rust-lang/book/*. Please see *CONTRIBUTING.md* at
188*https://github.com/rust-lang/book/blob/main/CONTRIBUTING.md* for more details.
189
190The source code for the examples in this book, errata, and other information
191are available at *https://www.nostarch.com/Rust2021/*.