@@ -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.1.0 (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.1.0 (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.1.0 (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
^
@@ -1788,7 +1788,7 @@ Let's try compiling what Cargo gave us:
1788
1788
1789
1789
``` {bash}
1790
1790
$ cargo build
1791
- Compiling guessing_game v0.0.1 (file:/home/you/projects/guessing_game)
1791
+ Compiling guessing_game v0.0.1 (file:/// home/you/projects/guessing_game)
1792
1792
$
1793
1793
```
1794
1794
@@ -1901,7 +1901,7 @@ Let's try to compile this using `cargo build`:
1901
1901
1902
1902
``` {notrust,no_run}
1903
1903
$ cargo build
1904
- Compiling guessing_game v0.0.1 (file:/home/you/projects/guessing_game)
1904
+ Compiling guessing_game v0.0.1 (file:/// home/you/projects/guessing_game)
1905
1905
src/main.rs:7:26: 7:34 error: the type of this value must be known in this context
1906
1906
src/main.rs:7 let secret_number = (rand::random() % 100i) + 1i;
1907
1907
^~~~~~~~
@@ -1949,7 +1949,7 @@ fn main() {
1949
1949
1950
1950
``` {notrust,ignore}
1951
1951
$ cargo build
1952
- Compiling guessing_game v0.0.1 (file:/home/you/projects/guessing_game)
1952
+ Compiling guessing_game v0.0.1 (file:/// home/you/projects/guessing_game)
1953
1953
$
1954
1954
```
1955
1955
@@ -2008,7 +2008,7 @@ And trying it out:
2008
2008
2009
2009
``` {notrust,ignore}
2010
2010
$ cargo build
2011
- Compiling guessing_game v0.0.1 (file:/home/you/projects/guessing_game)
2011
+ Compiling guessing_game v0.0.1 (file:/// home/you/projects/guessing_game)
2012
2012
$ ./target/guessing_game
2013
2013
Guess the number!
2014
2014
The secret number is: 57
@@ -2063,7 +2063,7 @@ If we try to compile, we'll get some errors:
2063
2063
2064
2064
``` {notrust,ignore}
2065
2065
$ cargo build
2066
- Compiling guessing_game v0.0.1 (file:/home/you/projects/guessing_game)
2066
+ Compiling guessing_game v0.0.1 (file:/// home/you/projects/guessing_game)
2067
2067
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)
2068
2068
src/main.rs:20 match cmp(input, secret_number) {
2069
2069
^~~~~
@@ -2117,7 +2117,7 @@ And try compiling again:
2117
2117
2118
2118
``` {notrust,ignore}
2119
2119
$ cargo build
2120
- Compiling guessing_game v0.0.1 (file:/home/you/projects/guessing_game)
2120
+ Compiling guessing_game v0.0.1 (file:/// home/you/projects/guessing_game)
2121
2121
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)
2122
2122
src/main.rs:20 match cmp(input, secret_number) {
2123
2123
^~~~~
@@ -2220,7 +2220,7 @@ Let's try it out!
2220
2220
2221
2221
``` {notrust,ignore}
2222
2222
$ cargo build
2223
- Compiling guessing_game v0.0.1 (file:/home/you/projects/guessing_game)
2223
+ Compiling guessing_game v0.0.1 (file:/// home/you/projects/guessing_game)
2224
2224
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)
2225
2225
src/main.rs:22 match cmp(input_num, secret_number) {
2226
2226
^~~~~~~~~
@@ -2279,8 +2279,8 @@ print an error message and return. Let's give this a shot:
2279
2279
2280
2280
``` {notrust,ignore}
2281
2281
$ cargo build
2282
- Compiling guessing_game v0.1.0 (file:/home/you/projects/guessing_game)
2283
- $ ./target/guessing_game
2282
+ Compiling guessing_game v0.1.0 (file:/// home/you/projects/guessing_game)
2283
+ $ ./target/guessing_game
2284
2284
Guess the number!
2285
2285
The secret number is: 17
2286
2286
Please input your guess.
@@ -2345,7 +2345,7 @@ Let's try it!
2345
2345
2346
2346
``` {notrust,ignore}
2347
2347
$ cargo build
2348
- Compiling guessing_game v0.0.1 (file:/home/you/projects/guessing_game)
2348
+ Compiling guessing_game v0.0.1 (file:/// home/you/projects/guessing_game)
2349
2349
$ ./target/guessing_game
2350
2350
Guess the number!
2351
2351
The secret number is: 58
@@ -2423,7 +2423,7 @@ that `return`? If we give a non-number answer, we'll `return` and quit. Observe:
2423
2423
2424
2424
``` {notrust,ignore}
2425
2425
$ cargo build
2426
- Compiling guessing_game v0.0.1 (file:/home/you/projects/guessing_game)
2426
+ Compiling guessing_game v0.0.1 (file:/// home/you/projects/guessing_game)
2427
2427
$ ./target/guessing_game
2428
2428
Guess the number!
2429
2429
The secret number is: 59
@@ -2556,7 +2556,7 @@ Now we should be good! Let's try:
2556
2556
2557
2557
``` {rust,ignore}
2558
2558
$ cargo build
2559
- Compiling guessing_game v0.0.1 (file:/home/you/projects/guessing_game)
2559
+ Compiling guessing_game v0.0.1 (file:/// home/you/projects/guessing_game)
2560
2560
$ ./target/guessing_game
2561
2561
Guess the number!
2562
2562
The secret number is: 61
@@ -2671,7 +2671,7 @@ Let's double check our work by compiling:
2671
2671
2672
2672
``` {bash,ignore}
2673
2673
$ cargo build
2674
- Compiling modules v0.1.0 (file:/home/you/projects/modules)
2674
+ Compiling modules v0.1.0 (file:/// home/you/projects/modules)
2675
2675
$ ./target/modules
2676
2676
Hello, world!
2677
2677
```
@@ -2732,7 +2732,7 @@ mod hello {
2732
2732
It gives an error:
2733
2733
2734
2734
``` {notrust,ignore}
2735
- Compiling modules v0.1.0 (file:/home/you/projects/modules)
2735
+ Compiling modules v0.1.0 (file:/// home/you/projects/modules)
2736
2736
src/main.rs:2:5: 2:23 error: function `print_hello` is private
2737
2737
src/main.rs:2 hello::print_hello();
2738
2738
^~~~~~~~~~~~~~~~~~
@@ -2754,9 +2754,19 @@ mod hello {
2754
2754
2755
2755
This will work:
2756
2756
2757
+ ``` {notrust,ignore}
2758
+ $ cargo build
2759
+ Compiling modules v0.1.0 (file:///home/you/projects/modules)
2760
+ $
2761
+ ```
2762
+
2763
+ Before we move on, let me show you one more Cargo command: ` run ` . ` cargo run `
2764
+ is kind of like ` cargo build ` , but it also then runs the produced exectuable.
2765
+ Try it out:
2766
+
2757
2767
``` {notrust,ignore}
2758
2768
$ cargo run
2759
- Compiling modules v0.1.0 (file:/home/steve/tmp/modules)
2769
+ Compiling modules v0.1.0 (file:/// home/steve/tmp/modules)
2760
2770
Running `target/modules`
2761
2771
Hello, world!
2762
2772
$
@@ -2806,7 +2816,7 @@ This doesn't _quite_ work yet. Try it:
2806
2816
2807
2817
``` {notrust,ignore}
2808
2818
$ cargo build
2809
- Compiling modules v0.1.0 (file:/home/you/projects/modules)
2819
+ Compiling modules v0.1.0 (file:/// home/you/projects/modules)
2810
2820
/home/you/projects/modules/src/lib.rs:2:5: 4:6 warning: code is never used: `print_hello`, #[warn(dead_code)] on by default
2811
2821
/home/you/projects/modules/src/lib.rs:2 pub fn print_hello() {
2812
2822
/home/you/projects/modules/src/lib.rs:3 println!("Hello, world!");
@@ -2842,7 +2852,7 @@ And everything should work:
2842
2852
2843
2853
``` {notrust,ignore}
2844
2854
$ cargo run
2845
- Compiling modules v0.1.0 (file:/home/you/projects/modules)
2855
+ Compiling modules v0.1.0 (file:/// home/you/projects/modules)
2846
2856
Running `target/modules`
2847
2857
Hello, world!
2848
2858
```
@@ -2908,7 +2918,7 @@ This should all compile as usual:
2908
2918
2909
2919
``` {notrust,ignore}
2910
2920
$ cargo build
2911
- Compiling modules v0.1.0 (file:/home/you/projects/modules)
2921
+ Compiling modules v0.1.0 (file:/// home/you/projects/modules)
2912
2922
$
2913
2923
```
2914
2924
@@ -3080,7 +3090,7 @@ And try it out:
3080
3090
3081
3091
``` {notrust,ignore}
3082
3092
$ cargo run
3083
- Compiling testing v0.1.0 (file:/home/you/projects/testing)
3093
+ Compiling testing v0.1.0 (file:/// home/you/projects/testing)
3084
3094
Running `target/testing`
3085
3095
Hello, world!
3086
3096
$
@@ -3113,7 +3123,7 @@ it `false`, so this test should fail. Let's try it!
3113
3123
3114
3124
``` {notrust,ignore}
3115
3125
$ cargo test
3116
- Compiling testing v0.1.0 (file:/home/you/projects/testing)
3126
+ Compiling testing v0.1.0 (file:/// home/you/projects/testing)
3117
3127
/home/you/projects/testing/src/main.rs:1:1: 3:2 warning: code is never used: `main`, #[warn(dead_code)] on by default
3118
3128
/home/you/projects/testing/src/main.rs:1 fn main() {
3119
3129
/home/you/projects/testing/src/main.rs:2 println!("Hello, world");
@@ -3146,7 +3156,7 @@ Lots of output! Let's break this down:
3146
3156
3147
3157
``` {notrust,ignore}
3148
3158
$ cargo test
3149
- Compiling testing v0.1.0 (file:/home/you/projects/testing)
3159
+ Compiling testing v0.1.0 (file:/// home/you/projects/testing)
3150
3160
```
3151
3161
3152
3162
You can run all of your tests with ` cargo test ` . This runs both your tests in
@@ -3221,7 +3231,7 @@ And then try to run our tests again:
3221
3231
3222
3232
``` {notrust,ignore}
3223
3233
$ cargo test
3224
- Compiling testing v0.1.0 (file:/home/you/projects/testing)
3234
+ Compiling testing v0.1.0 (file:/// home/you/projects/testing)
3225
3235
/home/you/projects/testing/src/main.rs:1:1: 3:2 warning: code is never used: `main`, #[warn(dead_code)] on by default
3226
3236
/home/you/projects/testing/src/main.rs:1 fn main() {
3227
3237
/home/you/projects/testing/src/main.rs:2 println!("Hello, world");
@@ -3260,7 +3270,7 @@ With this attribute, we won't get the warning:
3260
3270
3261
3271
``` {notrust,ignore}
3262
3272
$ cargo test
3263
- Compiling testing v0.1.0 (file:/home/you/projects/testing)
3273
+ Compiling testing v0.1.0 (file:/// home/you/projects/testing)
3264
3274
3265
3275
running 0 tests
3266
3276
@@ -3289,7 +3299,7 @@ And try to run the test:
3289
3299
3290
3300
``` {notrust,ignore}
3291
3301
$ cargo test
3292
- Compiling testing v0.1.0 (file:/home/youg/projects/testing)
3302
+ Compiling testing v0.1.0 (file:/// home/youg/projects/testing)
3293
3303
/home/youg/projects/testing/tests/lib.rs:3:18: 3:38 error: unresolved name `add_three_times_four`.
3294
3304
/home/youg/projects/testing/tests/lib.rs:3 let result = add_three_times_four(5i);
3295
3305
^~~~~~~~~~~~~~~~~~~~
@@ -3348,7 +3358,7 @@ Let's give it a run:
3348
3358
3349
3359
``` {ignore,notrust}
3350
3360
$ cargo test
3351
- Compiling testing v0.1.0 (file:/home/you/projects/testing)
3361
+ Compiling testing v0.1.0 (file:/// home/you/projects/testing)
3352
3362
3353
3363
running 0 tests
3354
3364
@@ -3388,7 +3398,7 @@ If you run `cargo test`, you should get the same output:
3388
3398
3389
3399
``` {ignore,notrust}
3390
3400
$ cargo test
3391
- Compiling testing v0.1.0 (file:/home/you/projects/testing)
3401
+ Compiling testing v0.1.0 (file:/// home/you/projects/testing)
3392
3402
3393
3403
running 0 tests
3394
3404
@@ -3432,7 +3442,7 @@ fn test_add_three() {
3432
3442
We'd get this error:
3433
3443
3434
3444
``` {notrust,ignore}
3435
- Compiling testing v0.1.0 (file:/home/you/projects/testing)
3445
+ Compiling testing v0.1.0 (file:/// home/you/projects/testing)
3436
3446
/home/you/projects/testing/tests/lib.rs:3:5: 3:24 error: function `add_three` is private
3437
3447
/home/you/projects/testing/tests/lib.rs:3 use testing::add_three;
3438
3448
^~~~~~~~~~~~~~~~~~~
@@ -3475,7 +3485,7 @@ Let's give it a shot:
3475
3485
3476
3486
``` {ignore,notrust}
3477
3487
$ cargo test
3478
- Compiling testing v0.1.0 (file:/home/you/projects/testing)
3488
+ Compiling testing v0.1.0 (file:/// home/you/projects/testing)
3479
3489
3480
3490
running 1 test
3481
3491
test test::test_times_four ... ok
0 commit comments