About the Author |
|
xv | |
About the Technical Reviewer |
|
xvii | |
Preface |
|
xix | |
Chapter 1 Getting Started |
|
1 | (8) |
|
|
1 | (1) |
|
|
2 | (2) |
|
Printing Combinations of Literal Strings |
|
|
4 | (1) |
|
Printing Several Lines of Text |
|
|
5 | (1) |
|
|
6 | (1) |
|
|
7 | (2) |
Chapter 2 Doing Arithmetic and Writing More Code |
|
9 | (8) |
|
|
9 | (1) |
|
Other Operations Between Integer Numbers |
|
|
10 | (1) |
|
Floating-Point Arithmetic |
|
|
11 | (2) |
|
|
13 | (1) |
|
|
14 | (3) |
Chapter 3 Naming Objects |
|
17 | (16) |
|
Associating Names to Values |
|
|
17 | (2) |
|
|
19 | (2) |
|
Not Mutated Mutable Variables |
|
|
21 | (1) |
|
|
22 | (2) |
|
|
24 | (1) |
|
|
25 | (2) |
|
|
27 | (1) |
|
Type Consistency in Assignments |
|
|
28 | (1) |
|
|
29 | (1) |
|
Change of Type and of Mutability |
|
|
30 | (1) |
|
Compound Assignment Operators |
|
|
31 | (1) |
|
Using the Functions of the Standard Library |
|
|
31 | (2) |
Chapter 4 Controlling Execution Flow |
|
33 | (14) |
|
Conditional Statements (if) |
|
|
33 | (3) |
|
|
36 | (2) |
|
Conditional Loops (while) |
|
|
38 | (2) |
|
|
40 | (1) |
|
|
41 | (3) |
|
|
44 | (3) |
Chapter 5 Using Data Sequences |
|
47 | (18) |
|
|
47 | (3) |
|
|
50 | (1) |
|
|
51 | (2) |
|
|
53 | (2) |
|
Arrays of Explicitly Specified Size |
|
|
55 | (1) |
|
|
56 | (1) |
|
|
57 | (2) |
|
Other Operations on Vectors |
|
|
59 | (2) |
|
|
61 | (1) |
|
|
62 | (1) |
|
Copying Arrays and Vectors |
|
|
63 | (2) |
Chapter 6 Using Primitive Types |
|
65 | (24) |
|
|
66 | (1) |
|
The Underscore in Numeric Literals |
|
|
67 | (1) |
|
|
67 | (2) |
|
The Various Kinds of Signed Integer Numbers |
|
|
69 | (2) |
|
Unsigned Integer Number Types |
|
|
71 | (1) |
|
Target-Dependent Integer-Number Types |
|
|
72 | (2) |
|
|
74 | (2) |
|
The Type Inference Algorithm |
|
|
76 | (1) |
|
Floating-Point Numeric Types |
|
|
77 | (1) |
|
|
78 | (1) |
|
Type Suffixes of Numeric Literals |
|
|
79 | (1) |
|
|
80 | (1) |
|
|
81 | (3) |
|
|
84 | (1) |
|
|
85 | (1) |
|
|
85 | (1) |
|
Discovering the Type of an Expression |
|
|
86 | (3) |
Chapter 7 Enumerations and Matching |
|
89 | (18) |
|
|
89 | (2) |
|
|
91 | (3) |
|
Relational Operators and Enums |
|
|
94 | (1) |
|
|
94 | (2) |
|
|
96 | (1) |
|
|
97 | (4) |
|
match Statements with Variables in Patterns |
|
|
101 | (1) |
|
|
102 | (1) |
|
Use of Guards in match Constructs |
|
|
103 | (1) |
|
if-let and while-let Constructs |
|
|
104 | (3) |
Chapter 8 Using Heterogeneous Data Structures |
|
107 | (8) |
|
|
107 | (2) |
|
|
109 | (3) |
|
|
112 | (1) |
|
|
113 | (2) |
Chapter 9 Defining Functions |
|
115 | (20) |
|
Defining and Invoking a Function |
|
|
115 | (1) |
|
Functions Defined After Their Use |
|
|
116 | (1) |
|
Functions Shadowing Other Functions |
|
|
117 | (1) |
|
Passing Arguments to a Function |
|
|
118 | (2) |
|
Passing Arguments by Value |
|
|
120 | (1) |
|
Returning a Value from a Function |
|
|
121 | (1) |
|
|
122 | (2) |
|
|
124 | (1) |
|
How to Change a Variable of the Caller |
|
|
125 | (2) |
|
Passing Arguments by Reference |
|
|
127 | (3) |
|
|
130 | (1) |
|
|
131 | (4) |
Chapter 10 Defining Generic Functions and Types |
|
135 | (16) |
|
Need of Generic Functions |
|
|
135 | (2) |
|
Defining and Using Generic Functions |
|
|
137 | (1) |
|
Inferring the Parametric Types |
|
|
138 | (1) |
|
Defining and Using Generic Structs |
|
|
139 | (2) |
|
|
141 | (2) |
|
Generic Arrays and Vectors |
|
|
143 | (1) |
|
|
143 | (1) |
|
The Option<T> Standard Enum |
|
|
144 | (2) |
|
The Result<T, E> Standard Enum |
|
|
146 | (1) |
|
Enum Standard Utility Functions |
|
|
147 | (4) |
Chapter 11 Allocating Memory |
|
151 | (20) |
|
The Various Kinds of Allocation |
|
|
151 | (1) |
|
|
152 | (2) |
|
|
154 | (1) |
|
|
155 | (6) |
|
Limitations of Stack Allocation |
|
|
161 | (3) |
|
|
164 | (1) |
|
|
165 | (1) |
|
|
166 | (1) |
|
Similarity with C and C++ |
|
|
167 | (1) |
|
|
168 | (2) |
|
|
170 | (1) |
Chapter 12 Data Implementation |
|
171 | (12) |
|
Discovering the Size of Objects |
|
|
171 | (1) |
|
|
172 | (1) |
|
The Sizes of the Primitive Types |
|
|
173 | (1) |
|
The Representation of Primitive Types |
|
|
174 | (1) |
|
Location of Bytes in Memory |
|
|
175 | (2) |
|
Sizes of Composite Data Types |
|
|
177 | (1) |
|
|
178 | (5) |
Chapter 13 Defining Closures |
|
183 | (8) |
|
The Need for Disposable Functions |
|
|
183 | (1) |
|
Capturing the Environment |
|
|
184 | (2) |
|
|
186 | (2) |
|
Closure Invocation Syntax |
|
|
188 | (3) |
Chapter 14 Using Changeable Strings |
|
191 | (12) |
|
|
191 | (3) |
|
|
194 | (1) |
|
|
195 | (3) |
|
|
198 | (1) |
|
Converting Static Strings to Dynamic Strings |
|
|
199 | (1) |
|
|
200 | (3) |
Chapter 15 Ranges and Slices |
|
203 | (14) |
|
|
203 | (3) |
|
|
206 | (1) |
|
|
207 | (3) |
|
|
210 | (2) |
|
|
212 | (1) |
|
|
213 | (1) |
|
Open-Ended Ranges and Slicing |
|
|
214 | (1) |
|
|
215 | (2) |
Chapter 16 Using Iterators |
|
217 | (26) |
|
|
217 | (2) |
|
|
219 | (2) |
|
Using String Iterators in for Loops |
|
|
221 | (1) |
|
|
222 | (1) |
|
Iterators over Vectors, Arrays, and Slices |
|
|
223 | (2) |
|
Iterators Generating References |
|
|
225 | (1) |
|
Iterations without Mutation |
|
|
226 | (1) |
|
|
226 | (2) |
|
Shorthand for Using Iterators in Loops |
|
|
228 | (1) |
|
|
229 | (1) |
|
An Iterator Adapter: filter |
|
|
229 | (1) |
|
|
230 | (1) |
|
The enumerate Iterator Adapter |
|
|
231 | (1) |
|
An Iterator Consumer: any |
|
|
232 | (2) |
|
The all Iterator Consumer |
|
|
234 | (1) |
|
The count Iterator Consumer |
|
|
235 | (1) |
|
The sum Iterator Consumer |
|
|
235 | (1) |
|
The min and max Iterator Consumers |
|
|
236 | (1) |
|
|
237 | (2) |
|
|
239 | (2) |
|
|
241 | (2) |
Chapter 17 Input/Output and Error Handling |
|
243 | (20) |
|
|
243 | (1) |
|
|
244 | (1) |
|
|
245 | (1) |
|
|
246 | (2) |
|
Proper Runtime Error Handling |
|
|
248 | (7) |
|
|
255 | (1) |
|
Converting a Value to a String |
|
|
256 | (1) |
|
Converting a String to a Value |
|
|
256 | (1) |
|
|
257 | (3) |
|
|
260 | (3) |
Chapter 18 Data Encapsulation |
|
263 | (14) |
|
|
263 | (2) |
|
|
265 | (3) |
|
The self and Self Keywords |
|
|
268 | (3) |
|
The mod and the pub Keywords |
|
|
271 | (4) |
|
|
275 | (2) |
Chapter 19 Using Traits |
|
277 | (32) |
|
|
277 | (3) |
|
|
280 | (3) |
|
Generic Functions with No Parameter Bounds |
|
|
283 | (1) |
|
|
284 | (2) |
|
Traits with Multiple Methods |
|
|
286 | (1) |
|
Generic Parameters with Multiple Bounds |
|
|
287 | (2) |
|
|
289 | (1) |
|
Adding Methods to External Types |
|
|
290 | (2) |
|
Standard Traits: Display and Debug |
|
|
292 | (2) |
|
|
294 | (4) |
|
|
298 | (8) |
|
The lterator Standard Trait |
|
|
306 | (3) |
Chapter 20 Object-Oriented Programming |
|
309 | (28) |
|
Peculiarities of Rust Object-Orientation |
|
|
309 | (1) |
|
|
310 | (4) |
|
|
314 | (7) |
|
Infallible Type Converters |
|
|
321 | (2) |
|
|
323 | (2) |
|
Composition Instead of Inheritance |
|
|
325 | (3) |
|
|
328 | (3) |
|
|
331 | (1) |
|
Implementation of Dynamic-Dispatch References |
|
|
332 | (2) |
|
Static vs. Dynamic Dispatch |
|
|
334 | (3) |
Chapter 21 Standard Library Collections |
|
337 | (18) |
|
|
337 | (1) |
|
|
338 | (1) |
|
Performing Arbitrary Insertions and Removals |
|
|
339 | (3) |
|
|
342 | (4) |
|
|
346 | (1) |
|
|
346 | (2) |
|
Ordered Sets and Unordered Sets |
|
|
348 | (4) |
|
Ordered Dictionaries and Unordered Dictionaries |
|
|
352 | (1) |
|
Collections in C++ and in Rust |
|
|
353 | (2) |
Chapter 22 Ownership, Moves, and Copies |
|
355 | (18) |
|
Deterministic Destruction |
|
|
355 | (3) |
|
|
358 | (1) |
|
|
359 | (3) |
|
Copying vs. Moving Performance |
|
|
362 | (1) |
|
Moving and Destroying Objects |
|
|
362 | (3) |
|
|
365 | (1) |
|
|
366 | (3) |
|
Making Types Cloneable or Copyable |
|
|
369 | (4) |
Chapter 23 Borrowing and Lifetimes |
|
373 | (22) |
|
Programming Errors when Using References |
|
|
373 | (4) |
|
|
377 | (1) |
|
|
378 | (1) |
|
How to Prevent Use After Drop Errors |
|
|
379 | (1) |
|
How to Prevent Use After Change by an Alias Errors |
|
|
380 | (2) |
|
The Need for Lifetime Specifiers in Returned References |
|
|
382 | (3) |
|
Usage and Meaning of Lifetime Specifiers |
|
|
385 | (3) |
|
Checking the Validity of Lifetime Specifiers |
|
|
388 | (4) |
|
Using the Lifetime Specifiers of Invoked Functions |
|
|
392 | (1) |
|
Advantage of Using Several Lifetime Specifiers for a Function |
|
|
393 | (2) |
Chapter 24 More About Lifetimes |
|
395 | (12) |
|
|
395 | (2) |
|
Lifetime Elision with Object-Oriented Programming |
|
|
397 | (1) |
|
The Need for Lifetime Specifiers in Structs Declarations |
|
|
398 | (3) |
|
Possible Lifetime Specifiers for Structs |
|
|
401 | (3) |
|
Lifetime Specifiers for Tuple-Structs and Enums |
|
|
404 | (1) |
|
Lifetime Specifiers for Mutable References |
|
|
404 | (3) |
Index |
|
407 | |