@@ -18,6 +18,8 @@ the Cargo
18
18
README] ( https://github.com/rust-lang/cargo#installing-cargo-from-nightlies )
19
19
for specific instructions about installing it.
20
20
21
+ ## Converting to Cargo
22
+
21
23
Let's convert Hello World to Cargo.
22
24
23
25
To Cargo-ify our project, we need to do two things: Make a ` Cargo.toml `
@@ -103,6 +105,62 @@ That's it! We've successfully built `hello_world` with Cargo. Even though our
103
105
program is simple, it's using much of the real tooling that you'll use for the
104
106
rest of your Rust career.
105
107
108
+ ## A New Project
109
+
110
+ You don't have to go through this whole process every time you want to start a new
111
+ project! Cargo has the ability to make a bare-bones project directory in which you
112
+ can start developing right away.
113
+
114
+ To start a new project with Cargo, use ` cargo new ` :
115
+
116
+ ``` {bash}
117
+ $ cargo new hello_world --bin
118
+ ```
119
+
120
+ We're passing ` --bin ` because we're making a binary program: if we
121
+ were making a library, we'd leave it off.
122
+
123
+ Let's check out what Cargo has generated for us:
124
+
125
+ ``` {bash}
126
+ $ cd hello_world
127
+ $ tree .
128
+ .
129
+ ├── Cargo.toml
130
+ └── src
131
+ └── main.rs
132
+
133
+ 1 directory, 2 files
134
+ ```
135
+
136
+ If you don't have the ` tree ` command, you can probably get it from your distro's package
137
+ manager. It's not necessary, but it's certainly useful.
138
+
139
+ This is all we need to get started. First, let's check out ` Cargo.toml ` :
140
+
141
+ ``` {toml}
142
+ [package]
143
+
144
+ name = "hello_world"
145
+ version = "0.0.1"
146
+ authors = ["Your Name <[email protected] >"]
147
+ ```
148
+
149
+ Cargo has populated this file with reasonable defaults based off the arguments
150
+ you gave it and your Git global config. You may notice that Cargo has also initialized
151
+ the ` hello_world ` directory as a Git repository.
152
+
153
+ Here's what's in ` src/main.rs ` :
154
+
155
+ ``` {rust}
156
+ fn main() {
157
+ println!("Hello, world!");
158
+ }
159
+ ```
160
+
161
+ Cargo has generated a "Hello World!" for us, and you're ready to start coding! A
162
+ much more in-depth guide to Cargo can be found [ here] ( http://doc.crates.io/guide.html ) .
163
+
106
164
Now that you've got the tools down, let's actually learn more about the Rust
107
165
language itself. These are the basics that will serve you well through the rest
108
- of your time with Rust.
166
+ of your time with Rust.
0 commit comments