@@ -342,7 +342,7 @@ Once you have this file in place, we should be ready to build! Try this:
342
342
343
343
``` {bash}
344
344
$ cargo build
345
- Compiling hello_world v0.1.0 (file:/home/yourname/projects/hello_world)
345
+ Compiling hello_world v0.0.1 (file:// /home/yourname/projects/hello_world)
346
346
$ ./target/hello_world
347
347
Hello, world!
348
348
```
@@ -486,7 +486,7 @@ You can use `cargo build` on the command line to build it. You'll get a warning,
486
486
but it will still print "Hello, world!":
487
487
488
488
``` {ignore,notrust}
489
- Compiling hello_world v0.1.0 (file:/home/you/projects/hello_world)
489
+ Compiling hello_world v0.0.1 (file:// /home/you/projects/hello_world)
490
490
src/hello_world.rs:2:9: 2:10 warning: unused variable: `x`, #[warn(unused_variable)] on by default
491
491
src/hello_world.rs:2 let x: int;
492
492
^
@@ -508,7 +508,7 @@ And try to build it. You'll get an error:
508
508
509
509
``` {bash}
510
510
$ cargo build
511
- Compiling hello_world v0.1.0 (file:/home/you/projects/hello_world)
511
+ Compiling hello_world v0.0.1 (file:// /home/you/projects/hello_world)
512
512
src/hello_world.rs:4:39: 4:40 error: use of possibly uninitialized variable: `x`
513
513
src/hello_world.rs:4 println!("The value of x is: {}", x);
514
514
^
@@ -1782,7 +1782,7 @@ Check out the generated `Cargo.toml`:
1782
1782
[package]
1783
1783
1784
1784
name = "guessing_game"
1785
- version = "0.1.0 "
1785
+ version = "0.0.1 "
1786
1786
authors = ["Your Name <you@example.com>"]
1787
1787
```
1788
1788
@@ -1793,15 +1793,15 @@ Finally, Cargo generated a hello, world for us. Check out `src/main.rs`:
1793
1793
1794
1794
``` {rust}
1795
1795
fn main() {
1796
- println!("Hello world!");
1796
+ println!("Hello, world!");
1797
1797
}
1798
1798
```
1799
1799
1800
1800
Let's try compiling what Cargo gave us:
1801
1801
1802
1802
``` {bash}
1803
1803
$ cargo build
1804
- Compiling guessing_game v0.1.0 (file:/home/you/projects/guessing_game)
1804
+ Compiling guessing_game v0.0.1 (file:// /home/you/projects/guessing_game)
1805
1805
$
1806
1806
```
1807
1807
@@ -1914,7 +1914,7 @@ Let's try to compile this using `cargo build`:
1914
1914
1915
1915
``` {notrust,no_run}
1916
1916
$ cargo build
1917
- Compiling guessing_game v0.1.0 (file:/home/you/projects/guessing_game)
1917
+ Compiling guessing_game v0.0.1 (file:// /home/you/projects/guessing_game)
1918
1918
src/main.rs:7:26: 7:34 error: the type of this value must be known in this context
1919
1919
src/main.rs:7 let secret_number = (rand::random() % 100i) + 1i;
1920
1920
^~~~~~~~
@@ -1962,7 +1962,7 @@ fn main() {
1962
1962
1963
1963
``` {notrust,ignore}
1964
1964
$ cargo build
1965
- Compiling guessing_game v0.1.0 (file:/home/you/projects/guessing_game)
1965
+ Compiling guessing_game v0.0.1 (file:// /home/you/projects/guessing_game)
1966
1966
$
1967
1967
```
1968
1968
@@ -2021,8 +2021,8 @@ And trying it out:
2021
2021
2022
2022
``` {notrust,ignore}
2023
2023
$ cargo build
2024
- Compiling guessing_game v0.1.0 (file:/home/you/projects/guessing_game)
2025
- $ ./target/guessing_game
2024
+ Compiling guessing_game v0.0.1 (file:// /home/you/projects/guessing_game)
2025
+ $ ./target/guessing_game
2026
2026
Guess the number!
2027
2027
The secret number is: 57
2028
2028
Please input your guess.
@@ -2076,7 +2076,7 @@ If we try to compile, we'll get some errors:
2076
2076
2077
2077
``` {notrust,ignore}
2078
2078
$ cargo build
2079
- Compiling guessing_game v0.1.0 (file:/home/you/projects/guessing_game)
2079
+ Compiling guessing_game v0.0.1 (file:// /home/you/projects/guessing_game)
2080
2080
src/main.rs:20:15: 20:20 error: mismatched types: expected `int` but found `collections::string::String` (expected int but found struct collections::string::String)
2081
2081
src/main.rs:20 match cmp(input, secret_number) {
2082
2082
^~~~~
@@ -2130,7 +2130,7 @@ And try compiling again:
2130
2130
2131
2131
``` {notrust,ignore}
2132
2132
$ cargo build
2133
- Compiling guessing_game v0.1.0 (file:/home/you/projects/guessing_game)
2133
+ Compiling guessing_game v0.0.1 (file:// /home/you/projects/guessing_game)
2134
2134
src/main.rs:20:15: 20:20 error: mismatched types: expected `uint` but found `collections::string::String` (expected uint but found struct collections::string::String)
2135
2135
src/main.rs:20 match cmp(input, secret_number) {
2136
2136
^~~~~
@@ -2161,7 +2161,7 @@ a function for that:
2161
2161
let input = io::stdin().read_line()
2162
2162
.ok()
2163
2163
.expect("Failed to read line");
2164
- let guess : Option<uint> = from_str(input.as_slice());
2164
+ let input_num : Option<uint> = from_str(input.as_slice());
2165
2165
```
2166
2166
2167
2167
The ` from_str ` function takes in a ` &str ` value and converts it into something.
@@ -2183,8 +2183,8 @@ In this case, we say `x` is a `uint` explicitly, so Rust is able to properly
2183
2183
tell ` random() ` what to generate. In a similar fashion, both of these work:
2184
2184
2185
2185
``` {rust,ignore}
2186
- let guess = from_str::<Option<uint>>("5");
2187
- let guess : Option<uint> = from_str("5");
2186
+ let input_num = from_str::<Option<uint>>("5");
2187
+ let input_num : Option<uint> = from_str("5");
2188
2188
```
2189
2189
2190
2190
In this case, I happen to prefer the latter, and in the ` random() ` case, I prefer
@@ -2233,7 +2233,7 @@ Let's try it out!
2233
2233
2234
2234
``` {notrust,ignore}
2235
2235
$ cargo build
2236
- Compiling guessing_game v0.1.0 (file:/home/you/projects/guessing_game)
2236
+ Compiling guessing_game v0.0.1 (file:// /home/you/projects/guessing_game)
2237
2237
src/main.rs:22:15: 22:24 error: mismatched types: expected `uint` but found `core::option::Option<uint>` (expected uint but found enum core::option::Option)
2238
2238
src/main.rs:22 match cmp(input_num, secret_number) {
2239
2239
^~~~~~~~~
@@ -2292,8 +2292,8 @@ print an error message and return. Let's give this a shot:
2292
2292
2293
2293
``` {notrust,ignore}
2294
2294
$ cargo build
2295
- Compiling guessing_game v0.1.0 (file:/home/you/projects/guessing_game)
2296
- $ ./target/guessing_game
2295
+ Compiling guessing_game v0.0.1 (file:// /home/you/projects/guessing_game)
2296
+ $ ./target/guessing_game
2297
2297
Guess the number!
2298
2298
The secret number is: 17
2299
2299
Please input your guess.
@@ -2358,8 +2358,8 @@ Let's try it!
2358
2358
2359
2359
``` {notrust,ignore}
2360
2360
$ cargo build
2361
- Compiling guessing_game v0.1.0 (file:/home/you/projects/guessing_game)
2362
- $ ./target/guessing_game
2361
+ Compiling guessing_game v0.0.1 (file:// /home/you/projects/guessing_game)
2362
+ $ ./target/guessing_game
2363
2363
Guess the number!
2364
2364
The secret number is: 58
2365
2365
Please input your guess.
@@ -2436,8 +2436,8 @@ that `return`? If we give a non-number answer, we'll `return` and quit. Observe:
2436
2436
2437
2437
``` {notrust,ignore}
2438
2438
$ cargo build
2439
- Compiling guessing_game v0.1.0 (file:/home/you/projects/guessing_game)
2440
- $ ./target/guessing_game
2439
+ Compiling guessing_game v0.0.1 (file:// /home/you/projects/guessing_game)
2440
+ $ ./target/guessing_game
2441
2441
Guess the number!
2442
2442
The secret number is: 59
2443
2443
Please input your guess.
@@ -2569,8 +2569,8 @@ Now we should be good! Let's try:
2569
2569
2570
2570
``` {rust,ignore}
2571
2571
$ cargo build
2572
- Compiling guessing_game v0.1.0 (file:/home/you/projects/guessing_game)
2573
- $ ./target/guessing_game
2572
+ Compiling guessing_game v0.0.1 (file:// /home/you/projects/guessing_game)
2573
+ $ ./target/guessing_game
2574
2574
Guess the number!
2575
2575
The secret number is: 61
2576
2576
Please input your guess.
@@ -2684,7 +2684,7 @@ Let's double check our work by compiling:
2684
2684
2685
2685
``` {bash,ignore}
2686
2686
$ cargo build
2687
- Compiling modules v0.1.0 (file:/home/you/projects/modules)
2687
+ Compiling modules v0.0.1 (file:// /home/you/projects/modules)
2688
2688
$ ./target/modules
2689
2689
Hello, world!
2690
2690
```
@@ -2745,7 +2745,7 @@ mod hello {
2745
2745
It gives an error:
2746
2746
2747
2747
``` {notrust,ignore}
2748
- Compiling modules v0.1.0 (file:/home/you/projects/modules)
2748
+ Compiling modules v0.0.1 (file:// /home/you/projects/modules)
2749
2749
src/main.rs:2:5: 2:23 error: function `print_hello` is private
2750
2750
src/main.rs:2 hello::print_hello();
2751
2751
^~~~~~~~~~~~~~~~~~
@@ -2769,7 +2769,7 @@ This will work:
2769
2769
2770
2770
``` {notrust,ignore}
2771
2771
$ cargo run
2772
- Compiling modules v0.1.0 (file:/home/steve/tmp /modules)
2772
+ Compiling modules v0.0.1 (file:/// home/you/projects /modules)
2773
2773
Running `target/modules`
2774
2774
Hello, world!
2775
2775
$
@@ -2819,7 +2819,7 @@ This doesn't _quite_ work yet. Try it:
2819
2819
2820
2820
``` {notrust,ignore}
2821
2821
$ cargo build
2822
- Compiling modules v0.1.0 (file:/home/you/projects/modules)
2822
+ Compiling modules v0.0.1 (file:// /home/you/projects/modules)
2823
2823
/home/you/projects/modules/src/lib.rs:2:5: 4:6 warning: code is never used: `print_hello`, #[warn(dead_code)] on by default
2824
2824
/home/you/projects/modules/src/lib.rs:2 pub fn print_hello() {
2825
2825
/home/you/projects/modules/src/lib.rs:3 println!("Hello, world!");
@@ -2855,7 +2855,7 @@ And everything should work:
2855
2855
2856
2856
``` {notrust,ignore}
2857
2857
$ cargo run
2858
- Compiling modules v0.1.0 (file:/home/you/projects/modules)
2858
+ Compiling modules v0.0.1 (file:// /home/you/projects/modules)
2859
2859
Running `target/modules`
2860
2860
Hello, world!
2861
2861
```
@@ -2921,7 +2921,7 @@ This should all compile as usual:
2921
2921
2922
2922
``` {notrust,ignore}
2923
2923
$ cargo build
2924
- Compiling modules v0.1.0 (file:/home/you/projects/modules)
2924
+ Compiling modules v0.0.1 (file:// /home/you/projects/modules)
2925
2925
$
2926
2926
```
2927
2927
@@ -3093,7 +3093,7 @@ And try it out:
3093
3093
3094
3094
``` {notrust,ignore}
3095
3095
$ cargo run
3096
- Compiling testing v0.1.0 (file:/home/you/projects/testing)
3096
+ Compiling testing v0.0.1 (file:// /home/you/projects/testing)
3097
3097
Running `target/testing`
3098
3098
Hello, world!
3099
3099
$
@@ -3126,7 +3126,7 @@ it `false`, so this test should fail. Let's try it!
3126
3126
3127
3127
``` {notrust,ignore}
3128
3128
$ cargo test
3129
- Compiling testing v0.1.0 (file:/home/you/projects/testing)
3129
+ Compiling testing v0.0.1 (file:// /home/you/projects/testing)
3130
3130
/home/you/projects/testing/src/main.rs:1:1: 3:2 warning: code is never used: `main`, #[warn(dead_code)] on by default
3131
3131
/home/you/projects/testing/src/main.rs:1 fn main() {
3132
3132
/home/you/projects/testing/src/main.rs:2 println!("Hello, world");
@@ -3159,7 +3159,7 @@ Lots of output! Let's break this down:
3159
3159
3160
3160
``` {notrust,ignore}
3161
3161
$ cargo test
3162
- Compiling testing v0.1.0 (file:/home/you/projects/testing)
3162
+ Compiling testing v0.0.1 (file:// /home/you/projects/testing)
3163
3163
```
3164
3164
3165
3165
You can run all of your tests with ` cargo test ` . This runs both your tests in
@@ -3234,7 +3234,7 @@ And then try to run our tests again:
3234
3234
3235
3235
``` {notrust,ignore}
3236
3236
$ cargo test
3237
- Compiling testing v0.1.0 (file:/home/you/projects/testing)
3237
+ Compiling testing v0.0.1 (file:// /home/you/projects/testing)
3238
3238
/home/you/projects/testing/src/main.rs:1:1: 3:2 warning: code is never used: `main`, #[warn(dead_code)] on by default
3239
3239
/home/you/projects/testing/src/main.rs:1 fn main() {
3240
3240
/home/you/projects/testing/src/main.rs:2 println!("Hello, world");
@@ -3273,7 +3273,7 @@ With this attribute, we won't get the warning:
3273
3273
3274
3274
``` {notrust,ignore}
3275
3275
$ cargo test
3276
- Compiling testing v0.1.0 (file:/home/you/projects/testing)
3276
+ Compiling testing v0.0.1 (file:// /home/you/projects/testing)
3277
3277
3278
3278
running 0 tests
3279
3279
@@ -3302,7 +3302,7 @@ And try to run the test:
3302
3302
3303
3303
``` {notrust,ignore}
3304
3304
$ cargo test
3305
- Compiling testing v0.1.0 (file:/home/youg/projects/testing)
3305
+ Compiling testing v0.0.1 (file:// /home/youg/projects/testing)
3306
3306
/home/youg/projects/testing/tests/lib.rs:3:18: 3:38 error: unresolved name `add_three_times_four`.
3307
3307
/home/youg/projects/testing/tests/lib.rs:3 let result = add_three_times_four(5i);
3308
3308
^~~~~~~~~~~~~~~~~~~~
@@ -3361,7 +3361,7 @@ Let's give it a run:
3361
3361
3362
3362
``` {ignore,notrust}
3363
3363
$ cargo test
3364
- Compiling testing v0.1.0 (file:/home/you/projects/testing)
3364
+ Compiling testing v0.0.1 (file:// /home/you/projects/testing)
3365
3365
3366
3366
running 0 tests
3367
3367
@@ -3401,7 +3401,7 @@ If you run `cargo test`, you should get the same output:
3401
3401
3402
3402
``` {ignore,notrust}
3403
3403
$ cargo test
3404
- Compiling testing v0.1.0 (file:/home/you/projects/testing)
3404
+ Compiling testing v0.0.1 (file:// /home/you/projects/testing)
3405
3405
3406
3406
running 0 tests
3407
3407
@@ -3445,7 +3445,7 @@ fn test_add_three() {
3445
3445
We'd get this error:
3446
3446
3447
3447
``` {notrust,ignore}
3448
- Compiling testing v0.1.0 (file:/home/you/projects/testing)
3448
+ Compiling testing v0.0.1 (file:// /home/you/projects/testing)
3449
3449
/home/you/projects/testing/tests/lib.rs:3:5: 3:24 error: function `add_three` is private
3450
3450
/home/you/projects/testing/tests/lib.rs:3 use testing::add_three;
3451
3451
^~~~~~~~~~~~~~~~~~~
@@ -3488,7 +3488,7 @@ Let's give it a shot:
3488
3488
3489
3489
``` {ignore,notrust}
3490
3490
$ cargo test
3491
- Compiling testing v0.1.0 (file:/home/you/projects/testing)
3491
+ Compiling testing v0.0.1 (file:// /home/you/projects/testing)
3492
3492
3493
3493
running 1 test
3494
3494
test test::test_times_four ... ok
0 commit comments