@@ -84,6 +84,7 @@ that variable
84
84
``` rust
85
85
fn main () {
86
86
let x : i32 = 20 ;
87
+ // ^^^^^ Type annotation
87
88
}
88
89
```
89
90
@@ -242,14 +243,14 @@ then the code for b is not executed
242
243
243
244
``` rust
244
245
fn main () {
245
- let c = 'z' ;
246
+ let c : char = 'z' ;
246
247
let z = 'ℤ' ;
247
248
let heart_eyed_cat = '😻' ;
248
249
}
249
250
```
250
251
251
- - A character is a 32-bit unicode scalar value
252
- - Very much unlike C/C++ where char is 8 bits
252
+ - A ` char ` is a 32-bit unicode scalar value
253
+ - Very much unlike C/C++ where ` char is 8 bits
253
254
254
255
<!--
255
256
- The final scalar type is the character, but it isn't often seen.
@@ -261,16 +262,22 @@ instead.
261
262
262
263
---
263
264
264
- # Strings
265
+ # ` String ` s
265
266
``` rust
266
- // Owned, heap-allocated string *slice*
267
- let s1 : String = String :: new (" Hello, 🌍!" );
267
+
268
+ let s1 = String :: new (" Hello, 🌍!" );
269
+ // ^^^^^^ Owned, heap-allocated string
268
270
```
269
271
270
- - Rust strings are UTF-8-encoded
272
+ - Rust ` String ` s are UTF-8-encoded
271
273
- Unlike C/C++: * Not null-terminated*
272
274
- Cannot be indexed like C strings
275
+ - ` String ` is heap-allocated
273
276
- Actually many types of strings in Rust
277
+ - ` CString `
278
+ - ` PathBuf `
279
+ - ` OsString `
280
+ - ...
274
281
275
282
<!--
276
283
- Rusts strings are complicated, because all strings are complicated
@@ -294,7 +301,7 @@ fn main() {
294
301
- Group multiple values into a single compound type
295
302
- Fixed size
296
303
- Different types per element
297
- - Create a tuple by writing a comma-separated list of values inside parentheses
304
+ - Create by writing a comma-separated list of values inside parentheses
298
305
299
306
::right::
300
307
@@ -406,9 +413,9 @@ fn also_returns_nothing() {
406
413
```
407
414
408
415
- The function boundary must always be explicitly annotated with types
409
- - Within the function body type inference may be used
416
+ - Type inference may be used in function body
410
417
- A function that returns nothing has the return type * unit* (` () ` )
411
- - The function body contains a series of statements optionally ending with an
418
+ - Function body contains a series of statements optionally ending with an
412
419
expression
413
420
414
421
<!--
@@ -440,6 +447,10 @@ fn my_fun() {
440
447
let x = 10 ;
441
448
```
442
449
450
+ ``` rust
451
+ return 42 ;
452
+ ```
453
+
443
454
<v-click >
444
455
445
456
``` rust
@@ -465,9 +476,9 @@ statements
465
476
466
477
- Expressions evaluate to a resulting value
467
478
- Expressions make up most of the Rust code you write
468
- - Includes all control flow such as ` if ` and ` while `
479
+ - Includes all control flow such as ` if ` and ` loop `
469
480
- Includes scoping braces (` { ` and ` } ` )
470
- - An expression can be turned into a statement by adding a semicolon ( ` ; ` )
481
+ - Semicolon ( ` ; ` ) turns expression into statement
471
482
472
483
``` rust {all|2-5}
473
484
fn main () {
0 commit comments