Skip to content

Commit 1a80dcb

Browse files
committedAug 2, 2014
Use cargo new.
Now that this feature exists, we should use it. Fixes #16078
1 parent d7cfc34 commit 1a80dcb

File tree

1 file changed

+18
-53
lines changed

1 file changed

+18
-53
lines changed
 

‎src/doc/guide.md

+18-53
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ Put this inside:
316316
317317
name = "hello_world"
318318
version = "0.1.0"
319-
authors = [ "someone@example.com" ]
319+
authors = [ "Your name <you@example.com>" ]
320320
321321
[[bin]]
322322
@@ -1594,41 +1594,45 @@ taken to the screen. Sound good?
15941594

15951595
## Set up
15961596

1597-
Let's set up a new project. Go to your projects directory, and make a new
1598-
directory for the project, as well as a `src` directory for our code:
1597+
Let's set up a new project. Go to your projects directory. Remember how we
1598+
had to create our directory structure and a `Cargo.toml` for `hello_world`? Cargo
1599+
has a command that does that for us. Let's give it a shot:
15991600

16001601
```{bash}
16011602
$ cd ~/projects
1602-
$ mkdir guessing_game
1603+
$ cargo new guessing_game --bin
16031604
$ cd guessing_game
1604-
$ mkdir src
16051605
```
16061606

1607-
Great. Next, let's make a `Cargo.toml` file so Cargo knows how to build our
1608-
project:
1607+
We pass the name of our project to `cargo new`, and then the `--bin` flag,
1608+
since we're making a binary, rather than a library.
1609+
1610+
Check out the generated `Cargo.toml`:
16091611

16101612
```{ignore}
16111613
[package]
16121614
16131615
name = "guessing_game"
16141616
version = "0.1.0"
1615-
authors = [ "someone@example.com" ]
1617+
authors = ["Your Name <you@example.com>"]
16161618
16171619
[[bin]]
16181620
16191621
name = "guessing_game"
16201622
```
16211623

1622-
Finally, we need our source file. Let's just make it hello world for now, so we
1623-
can check that our setup works. In `src/guessing_game.rs`:
1624+
Cargo gets this information from your environment. If it's not correct, go ahead
1625+
and fix that.
1626+
1627+
Finally, Cargo generated a hello, world for us. Check out `src/main.rs`:
16241628

16251629
```{rust}
16261630
fn main() {
16271631
println!("Hello world!");
16281632
}
16291633
```
16301634

1631-
Let's make sure that worked:
1635+
Let's try compiling what Cargo gave us:
16321636

16331637
```{bash}
16341638
$ cargo build
@@ -1883,7 +1887,6 @@ fn cmp(a: int, b: int) -> Ordering {
18831887
If we try to compile, we'll get some errors:
18841888

18851889
```{notrust,ignore}
1886-
$ cargo build
18871890
$ cargo build
18881891
Compiling guessing_game v0.1.0 (file:/home/you/projects/guessing_game)
18891892
src/guessing_game.rs:20:15: 20:20 error: mismatched types: expected `int` but found `collections::string::String` (expected int but found struct collections::string::String)
@@ -2486,27 +2489,7 @@ Enough talk, let's build something! Let's make a new project called `modules`.
24862489

24872490
```{bash,ignore}
24882491
$ cd ~/projects
2489-
$ mkdir modules
2490-
$ cd modules
2491-
$ mkdir src
2492-
```
2493-
2494-
We need to make our two 'hello world' files. In `src/main.rs`:
2495-
2496-
```{rust}
2497-
fn main() {
2498-
println!("Hello, world!");
2499-
}
2500-
```
2501-
2502-
And in `Cargo.toml`:
2503-
2504-
```{notrust,ignore}
2505-
[package]
2506-
2507-
name = "modules"
2508-
version = "0.1.0"
2509-
authors = [ "someone@example.com" ]
2492+
$ cargo new modules --bin
25102493
```
25112494

25122495
Let's double check our work by compiling:
@@ -2924,34 +2907,16 @@ now: make a new project:
29242907

29252908
```{bash,ignore}
29262909
$ cd ~/projects
2927-
$ mkdir testing
2910+
$ cargo new testing --bin
29282911
$ cd testing
2929-
$ mkdir test
2930-
```
2931-
2932-
In `src/main.rs`:
2933-
2934-
```{rust}
2935-
fn main() {
2936-
println!("Hello, world!");
2937-
}
2938-
```
2939-
2940-
And in `Cargo.toml`:
2941-
2942-
```{notrust,ignore}
2943-
[package]
2944-
2945-
name = "testing"
2946-
version = "0.1.0"
2947-
authors = [ "someone@example.com" ]
29482912
```
29492913

29502914
And try it out:
29512915

29522916
```{notrust,ignore}
29532917
$ cargo run
29542918
Compiling testing v0.1.0 (file:/home/you/projects/testing)
2919+
Running `target/testing`
29552920
Hello, world!
29562921
$
29572922
```

0 commit comments

Comments
 (0)