Skip to content

Commit dbb0cee

Browse files
committed
auto merge of #16474 : MatejLach/rust/cargorun_fix, r=steveklabnik
This fixes #16451. While moving things around, I also removed a bunch of unnecessary whitespace, however I can put it back in if that's undesired. Thanks.
2 parents f8e0ede + bede9ec commit dbb0cee

File tree

1 file changed

+30
-26
lines changed

1 file changed

+30
-26
lines changed

src/doc/guide.md

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,7 @@ while !done {
13601360
```
13611361

13621362
`while` loops are the correct choice when you're not sure how many times
1363-
you need to loop.
1363+
you need to loop.
13641364

13651365
If you need an infinite loop, you may be tempted to write this:
13661366

@@ -1650,7 +1650,7 @@ a full line of input. Nice and easy.
16501650
.ok().expect("Failed to read line");
16511651
```
16521652

1653-
Do you remember this code?
1653+
Do you remember this code?
16541654

16551655
```
16561656
enum OptionalInt {
@@ -1796,6 +1796,21 @@ Excellent! Open up your `src/main.rs` again. We'll be writing all of
17961796
our code in this file. We'll talk about multiple-file projects later on in the
17971797
guide.
17981798

1799+
Before we move on, let me show you one more Cargo command: `run`. `cargo run`
1800+
is kind of like `cargo build`, but it also then runs the produced exectuable.
1801+
Try it out:
1802+
1803+
```{notrust,ignore}
1804+
$ cargo run
1805+
Compiling guessing_game v0.1.0 (file:/home/you/projects/guessing_game)
1806+
Running `target/guessing_game`
1807+
Hello, world!
1808+
$
1809+
```
1810+
1811+
Great! The `run` command comes in handy when you need to rapidly iterate on a project.
1812+
Our game is just such a project, we need to quickly test each iteration before moving on to the next one.
1813+
17991814
## Processing a Guess
18001815

18011816
Let's get to it! The first thing we need to do for our guessing game is
@@ -1933,19 +1948,19 @@ $
19331948
Excellent! Try running our new program a few times:
19341949

19351950
```{notrust,ignore}
1936-
$ ./target/guessing_game
1951+
$ ./target/guessing_game
19371952
Guess the number!
19381953
The secret number is: 7
19391954
Please input your guess.
19401955
4
19411956
You guessed: 4
1942-
$ ./target/guessing_game
1957+
$ ./target/guessing_game
19431958
Guess the number!
19441959
The secret number is: 83
19451960
Please input your guess.
19461961
5
19471962
You guessed: 5
1948-
$ ./target/guessing_game
1963+
$ ./target/guessing_game
19491964
Guess the number!
19501965
The secret number is: -29
19511966
Please input your guess.
@@ -1986,7 +2001,7 @@ And trying it out:
19862001
```{notrust,ignore}
19872002
$ cargo build
19882003
Compiling guessing_game v0.1.0 (file:/home/you/projects/guessing_game)
1989-
$ ./target/guessing_game
2004+
$ ./target/guessing_game
19902005
Guess the number!
19912006
The secret number is: 57
19922007
Please input your guess.
@@ -2022,7 +2037,7 @@ fn main() {
20222037
20232038
println!("You guessed: {}", input);
20242039
2025-
match cmp(input, secret_number) {
2040+
match cmp(input, secret_number) {
20262041
Less => println!("Too small!"),
20272042
Greater => println!("Too big!"),
20282043
Equal => { println!("You win!"); },
@@ -2106,7 +2121,7 @@ a `String` instead! That's because our `input` variable is coming from the
21062121
standard input, and you can guess anything. Try it:
21072122

21082123
```{notrust,ignore}
2109-
$ ./target/guessing_game
2124+
$ ./target/guessing_game
21102125
Guess the number!
21112126
The secret number is: 73
21122127
Please input your guess.
@@ -2257,7 +2272,7 @@ print an error message and return. Let's give this a shot:
22572272
```{notrust,ignore}
22582273
$ cargo build
22592274
Compiling guessing_game v0.1.0 (file:/home/you/projects/guessing_game)
2260-
$ ./target/guessing_game
2275+
$ ./target/guessing_game
22612276
Guess the number!
22622277
The secret number is: 17
22632278
Please input your guess.
@@ -2323,7 +2338,7 @@ Let's try it!
23232338
```{notrust,ignore}
23242339
$ cargo build
23252340
Compiling guessing_game v0.1.0 (file:/home/you/projects/guessing_game)
2326-
$ ./target/guessing_game
2341+
$ ./target/guessing_game
23272342
Guess the number!
23282343
The secret number is: 58
23292344
Please input your guess.
@@ -2401,7 +2416,7 @@ that `return`? If we give a non-number answer, we'll `return` and quit. Observe:
24012416
```{notrust,ignore}
24022417
$ cargo build
24032418
Compiling guessing_game v0.1.0 (file:/home/you/projects/guessing_game)
2404-
$ ./target/guessing_game
2419+
$ ./target/guessing_game
24052420
Guess the number!
24062421
The secret number is: 59
24072422
Please input your guess.
@@ -2534,7 +2549,7 @@ Now we should be good! Let's try:
25342549
```{rust,ignore}
25352550
$ cargo build
25362551
Compiling guessing_game v0.1.0 (file:/home/you/projects/guessing_game)
2537-
$ ./target/guessing_game
2552+
$ ./target/guessing_game
25382553
Guess the number!
25392554
The secret number is: 61
25402555
Please input your guess.
@@ -2731,16 +2746,6 @@ mod hello {
27312746

27322747
This will work:
27332748

2734-
```{notrust,ignore}
2735-
$ cargo build
2736-
Compiling modules v0.1.0 (file:/home/you/projects/modules)
2737-
$
2738-
```
2739-
2740-
Before we move on, let me show you one more Cargo command: `run`. `cargo run`
2741-
is kind of like `cargo build`, but it also then runs the produced exectuable.
2742-
Try it out:
2743-
27442749
```{notrust,ignore}
27452750
$ cargo run
27462751
Compiling modules v0.1.0 (file:/home/steve/tmp/modules)
@@ -3647,14 +3652,14 @@ In order to truly understand this error, we have to learn a few new concepts:
36473652
All of our references so far have been to variables we've created on the stack.
36483653
In Rust, the simplest way to allocate heap variables is using a *box*. To
36493654
create a box, use the `box` keyword:
3650-
3655+
36513656
```{rust}
36523657
let x = box 5i;
36533658
```
36543659

36553660
This allocates an integer `5` on the heap, and creates a binding `x` that
36563661
refers to it.. The great thing about boxed pointers is that we don't have to
3657-
manually free this allocation! If we write
3662+
manually free this allocation! If we write
36583663

36593664
```{rust}
36603665
{
@@ -4189,7 +4194,7 @@ the match:
41894194

41904195
```{rust,ignore}
41914196
let x = inverse(25.0f64);
4192-
println!("{}", x + 2.0f64); // error: binary operation `+` cannot be applied
4197+
println!("{}", x + 2.0f64); // error: binary operation `+` cannot be applied
41934198
// to type `core::result::Result<f64,collections::string::String>`
41944199
```
41954200

@@ -4700,4 +4705,3 @@ fail.
47004705
# Macros
47014706

47024707
# Unsafe
4703-

0 commit comments

Comments
 (0)