@@ -75,14 +75,14 @@ Let's get to it! The first thing we need to do for our guessing game is
75
75
allow our player to input a guess. Put this in your ` src/main.rs ` :
76
76
77
77
``` {rust,no_run}
78
- use std::io ;
78
+ use std::old_io ;
79
79
80
80
fn main() {
81
81
println!("Guess the number!");
82
82
83
83
println!("Please input your guess.");
84
84
85
- let input = io ::stdin().read_line()
85
+ let input = old_io ::stdin().read_line()
86
86
.ok()
87
87
.expect("Failed to read line");
88
88
@@ -121,7 +121,7 @@ explanatory text, and then an example. Let's try to modify our code to add in th
121
121
` random ` function and see what happens:
122
122
123
123
``` {rust,ignore}
124
- use std::io ;
124
+ use std::old_io ;
125
125
use std::rand;
126
126
127
127
fn main() {
@@ -133,7 +133,7 @@ fn main() {
133
133
134
134
println!("Please input your guess.");
135
135
136
- let input = io ::stdin().read_line()
136
+ let input = old_io ::stdin().read_line()
137
137
.ok()
138
138
.expect("Failed to read line");
139
139
@@ -180,7 +180,7 @@ This says "please give me a random `i32` value." We can change our code to use
180
180
this hint:
181
181
182
182
``` {rust,no_run}
183
- use std::io ;
183
+ use std::old_io ;
184
184
use std::rand;
185
185
186
186
fn main() {
@@ -192,7 +192,7 @@ fn main() {
192
192
193
193
println!("Please input your guess.");
194
194
195
- let input = io ::stdin().read_line()
195
+ let input = old_io ::stdin().read_line()
196
196
.ok()
197
197
.expect("Failed to read line");
198
198
@@ -233,7 +233,7 @@ unsigned integer approach. If we want a random positive number, we should ask fo
233
233
a random positive number. Our code looks like this now:
234
234
235
235
``` {rust,no_run}
236
- use std::io ;
236
+ use std::old_io ;
237
237
use std::rand;
238
238
239
239
fn main() {
@@ -245,7 +245,7 @@ fn main() {
245
245
246
246
println!("Please input your guess.");
247
247
248
- let input = io ::stdin().read_line()
248
+ let input = old_io ::stdin().read_line()
249
249
.ok()
250
250
.expect("Failed to read line");
251
251
@@ -276,7 +276,7 @@ two numbers. Let's add that in, along with a `match` statement to compare our
276
276
guess to the secret number:
277
277
278
278
``` {rust,ignore}
279
- use std::io ;
279
+ use std::old_io ;
280
280
use std::rand;
281
281
use std::cmp::Ordering;
282
282
@@ -289,7 +289,7 @@ fn main() {
289
289
290
290
println!("Please input your guess.");
291
291
292
- let input = io ::stdin().read_line()
292
+ let input = old_io ::stdin().read_line()
293
293
.ok()
294
294
.expect("Failed to read line");
295
295
@@ -331,7 +331,7 @@ but we've given it unsigned integers. In this case, the fix is easy, because
331
331
we wrote the `cmp` function! Let' s change it to take ` u32` s:
332
332
333
333
` ` ` {rust,ignore}
334
- use std::io ;
334
+ use std::old_io ;
335
335
use std::rand;
336
336
use std::cmp::Ordering;
337
337
@@ -344,7 +344,7 @@ fn main() {
344
344
345
345
println! (" Please input your guess." );
346
346
347
- let input = io ::stdin().read_line ()
347
+ let input = old_io ::stdin().read_line ()
348
348
.ok ()
349
349
.expect(" Failed to read line" );
350
350
@@ -397,7 +397,7 @@ Anyway, we have a `String`, but we need a `u32`. What to do? Well, there's
397
397
a function for that:
398
398
399
399
` ` ` {rust,ignore}
400
- let input = io ::stdin().read_line ()
400
+ let input = old_io ::stdin().read_line ()
401
401
.ok ()
402
402
.expect(" Failed to read line" );
403
403
let input_num: Option< u32> = input.parse ();
@@ -429,7 +429,7 @@ let input_num: Option<u32> = "5".parse(); // input_num: Option<u32>
429
429
Anyway, with us now converting our input to a number, our code looks like this:
430
430
431
431
` ` ` {rust,ignore}
432
- use std::io ;
432
+ use std::old_io ;
433
433
use std::rand;
434
434
use std::cmp::Ordering;
435
435
@@ -442,7 +442,7 @@ fn main() {
442
442
443
443
println! (" Please input your guess." );
444
444
445
- let input = io ::stdin().read_line ()
445
+ let input = old_io ::stdin().read_line ()
446
446
.ok ()
447
447
.expect(" Failed to read line" );
448
448
let input_num: Option< u32> = input.parse ();
@@ -479,7 +479,7 @@ need to unwrap the Option. If you remember from before, `match` is a great way
479
479
to do that. Try this code:
480
480
481
481
```{rust,no_run}
482
- use std::io ;
482
+ use std::old_io ;
483
483
use std::rand;
484
484
use std::cmp::Ordering;
485
485
@@ -492,7 +492,7 @@ fn main() {
492
492
493
493
println!("Please input your guess.");
494
494
495
- let input = io ::stdin().read_line()
495
+ let input = old_io ::stdin().read_line()
496
496
.ok()
497
497
.expect("Failed to read line");
498
498
let input_num: Option<u32> = input.parse();
@@ -546,7 +546,7 @@ method we can use defined on them: `trim()`. One small modification, and our
546
546
code looks like this:
547
547
548
548
```{rust,no_run}
549
- use std::io ;
549
+ use std::old_io ;
550
550
use std::rand;
551
551
use std::cmp::Ordering;
552
552
@@ -559,7 +559,7 @@ fn main() {
559
559
560
560
println!("Please input your guess.");
561
561
562
- let input = io ::stdin().read_line()
562
+ let input = old_io ::stdin().read_line()
563
563
.ok()
564
564
.expect("Failed to read line");
565
565
let input_num: Option<u32> = input.trim().parse();
@@ -620,7 +620,7 @@ As we already discussed, the `loop` keyword gives us an infinite loop.
620
620
Let' s add that in:
621
621
622
622
` ` ` {rust,no_run}
623
- use std::io ;
623
+ use std::old_io ;
624
624
use std::rand;
625
625
use std::cmp::Ordering;
626
626
@@ -635,7 +635,7 @@ fn main() {
635
635
636
636
println! (" Please input your guess." );
637
637
638
- let input = io ::stdin().read_line ()
638
+ let input = old_io ::stdin().read_line ()
639
639
.ok ()
640
640
.expect(" Failed to read line" );
641
641
let input_num: Option< u32> = input.trim().parse ();
@@ -696,7 +696,7 @@ Ha! `quit` actually quits. As does any other non-number input. Well, this is
696
696
suboptimal to say the least. First, let' s actually quit when you win the game:
697
697
698
698
```{rust,no_run}
699
- use std::io ;
699
+ use std::old_io ;
700
700
use std::rand;
701
701
use std::cmp::Ordering;
702
702
@@ -711,7 +711,7 @@ fn main() {
711
711
712
712
println!("Please input your guess.");
713
713
714
- let input = io ::stdin().read_line()
714
+ let input = old_io ::stdin().read_line()
715
715
.ok()
716
716
.expect("Failed to read line");
717
717
let input_num: Option<u32> = input.trim().parse();
@@ -752,7 +752,7 @@ we don't want to quit, we just want to ignore it. Change that `return` to
752
752
753
753
754
754
```{rust,no_run}
755
- use std::io ;
755
+ use std::old_io ;
756
756
use std::rand;
757
757
use std::cmp::Ordering;
758
758
@@ -767,7 +767,7 @@ fn main() {
767
767
768
768
println!("Please input your guess.");
769
769
770
- let input = io ::stdin().read_line()
770
+ let input = old_io ::stdin().read_line()
771
771
.ok()
772
772
.expect("Failed to read line");
773
773
let input_num: Option<u32> = input.trim().parse();
@@ -831,7 +831,7 @@ think of what it is? That's right, we don't want to print out the secret number.
831
831
It was good for testing, but it kind of ruins the game. Here' s our final source:
832
832
833
833
```{rust,no_run}
834
- use std::io ;
834
+ use std::old_io ;
835
835
use std::rand;
836
836
use std::cmp::Ordering;
837
837
@@ -844,7 +844,7 @@ fn main() {
844
844
845
845
println!("Please input your guess.");
846
846
847
- let input = io ::stdin().read_line()
847
+ let input = old_io ::stdin().read_line()
848
848
.ok()
849
849
.expect("Failed to read line");
850
850
let input_num: Option<u32> = input.trim().parse();
0 commit comments