@@ -2021,7 +2021,7 @@ And trying it out:
2021
2021
``` {notrust,ignore}
2022
2022
$ cargo build
2023
2023
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
2024
- $ ./target/guessing_game
2024
+ $ ./target/guessing_game
2025
2025
Guess the number!
2026
2026
The secret number is: 57
2027
2027
Please input your guess.
@@ -2292,7 +2292,7 @@ print an error message and return. Let's give this a shot:
2292
2292
``` {notrust,ignore}
2293
2293
$ cargo build
2294
2294
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
2295
- $ ./target/guessing_game
2295
+ $ ./target/guessing_game
2296
2296
Guess the number!
2297
2297
The secret number is: 17
2298
2298
Please input your guess.
@@ -2358,11 +2358,11 @@ Let's try it!
2358
2358
``` {notrust,ignore}
2359
2359
$ cargo build
2360
2360
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
2361
- $ ./target/guessing_game
2361
+ $ ./target/guessing_game
2362
2362
Guess the number!
2363
2363
The secret number is: 58
2364
2364
Please input your guess.
2365
- 76
2365
+ 76
2366
2366
You guessed: 76
2367
2367
Too big!
2368
2368
$
@@ -2436,7 +2436,7 @@ that `return`? If we give a non-number answer, we'll `return` and quit. Observe:
2436
2436
``` {notrust,ignore}
2437
2437
$ cargo build
2438
2438
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
2439
- $ ./target/guessing_game
2439
+ $ ./target/guessing_game
2440
2440
Guess the number!
2441
2441
The secret number is: 59
2442
2442
Please input your guess.
@@ -2569,7 +2569,7 @@ Now we should be good! Let's try:
2569
2569
``` {rust,ignore}
2570
2570
$ cargo build
2571
2571
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
2572
- $ ./target/guessing_game
2572
+ $ ./target/guessing_game
2573
2573
Guess the number!
2574
2574
The secret number is: 61
2575
2575
Please input your guess.
@@ -3718,18 +3718,18 @@ That's a lot to take in. It's also one of the _most_ important concepts in
3718
3718
all of Rust. Let's see this syntax in action:
3719
3719
3720
3720
``` {rust}
3721
- {
3721
+ {
3722
3722
let x = 5i; // x is the owner of this integer, which is memory on the stack.
3723
3723
3724
3724
// other code here...
3725
-
3725
+
3726
3726
} // privilege 1: when x goes out of scope, this memory is deallocated
3727
3727
3728
3728
/// this function borrows an integer. It's given back automatically when the
3729
3729
/// function returns.
3730
- fn foo(x: &int) -> &int { x }
3730
+ fn foo(x: &int) -> &int { x }
3731
3731
3732
- {
3732
+ {
3733
3733
let x = 5i; // x is the owner of this integer, which is memory on the stack.
3734
3734
3735
3735
// privilege 2: you may lend that resource, to as many borrowers as you'd like
@@ -3739,14 +3739,14 @@ fn foo(x: &int) -> &int { x }
3739
3739
foo(&x); // functions can borrow too!
3740
3740
3741
3741
let a = &x; // we can do this alllllll day!
3742
- }
3742
+ }
3743
3743
3744
- {
3744
+ {
3745
3745
let mut x = 5i; // x is the owner of this integer, which is memory on the stack.
3746
3746
3747
3747
let y = &mut x; // privilege 3: you may lend that resource to a single borrower,
3748
3748
// mutably
3749
- }
3749
+ }
3750
3750
```
3751
3751
3752
3752
If you are a borrower, you get a few privileges as well, but must also obey a
@@ -4535,7 +4535,7 @@ let one_to_one_hundred = range(0i, 100i).collect();
4535
4535
```
4536
4536
4537
4537
As you can see, we call ` collect() ` on our iterator. ` collect() ` takes
4538
- as many values as the iterator will give it, and returns a collection
4538
+ as many values as the iterator will give it, and returns a collection
4539
4539
of the results. So why won't this compile? Rust can't determine what
4540
4540
type of things you want to collect, and so you need to let it know.
4541
4541
Here's the version that does compile:
@@ -5508,7 +5508,7 @@ fn main() {
5508
5508
}
5509
5509
```
5510
5510
5511
- Whew! This isn't too terrible. You can see that we still ` let x = 5i ` ,
5511
+ Whew! This isn't too terrible. You can see that we still ` let x = 5i ` ,
5512
5512
but then things get a little bit hairy. Three more bindings get set: a
5513
5513
static format string, an argument vector, and the aruments. We then
5514
5514
invoke the ` println_args ` function with the generated arguments.
0 commit comments