@@ -139,14 +139,15 @@ the documentation for your shell for more details.
139
139
140
140
Let's make a new source file next. I'm going to use the syntax `editor
141
141
filename` to represent editing a file in these examples, but you should use
142
- whatever method you want. We'll call our file ` hello_world .rs` :
142
+ whatever method you want. We'll call our file ` main .rs` :
143
143
144
144
``` {bash}
145
- $ editor hello_world .rs
145
+ $ editor main .rs
146
146
```
147
147
148
148
Rust files always end in a ` .rs ` extension. If you're using more than one word
149
- in your file name, use an underscore. ` hello_world.rs ` versus ` goodbye.rs ` .
149
+ in your file name, use an underscore. ` hello_world.rs ` rather than
150
+ ` helloworld.rs ` .
150
151
151
152
Now that you've got your file open, type this in:
152
153
@@ -159,7 +160,7 @@ fn main() {
159
160
Save the file, and then type this into your terminal window:
160
161
161
162
``` {bash}
162
- $ rustc hello_world .rs
163
+ $ rustc main .rs
163
164
$ ./hello_world # or hello_world.exe on Windows
164
165
Hello, world!
165
166
```
@@ -221,22 +222,22 @@ Finally, actually **compiling** and **running** our program. We can compile
221
222
with our compiler, ` rustc ` , by passing it the name of our source file:
222
223
223
224
``` {bash}
224
- $ rustc hello_world .rs
225
+ $ rustc main .rs
225
226
```
226
227
227
228
This is similar to ` gcc ` or ` clang ` , if you come from a C or C++ background. Rust
228
229
will output a binary executable. You can see it with ` ls ` :
229
230
230
231
``` {bash}
231
232
$ ls
232
- hello_world hello_world .rs
233
+ main main .rs
233
234
```
234
235
235
236
Or on Windows:
236
237
237
238
``` {bash}
238
239
$ dir
239
- hello_world .exe hello_world .rs
240
+ main .exe main .rs
240
241
```
241
242
242
243
There are now two files: our source code, with the ` .rs ` extension, and the
@@ -293,7 +294,7 @@ do that part first:
293
294
294
295
``` {bash}
295
296
$ mkdir src
296
- $ mv hello_world .rs src/hello_world .rs
297
+ $ mv main .rs src/main .rs
297
298
```
298
299
299
300
Cargo expects your source files to live inside a ` src ` directory. That leaves
@@ -461,9 +462,9 @@ let x;
461
462
...we'll get an error:
462
463
463
464
``` {ignore}
464
- src/hello_world .rs:2:9: 2:10 error: cannot determine a type for this local variable: unconstrained type
465
- src/hello_world .rs:2 let x;
466
- ^
465
+ src/main .rs:2:9: 2:10 error: cannot determine a type for this local variable: unconstrained type
466
+ src/main .rs:2 let x;
467
+ ^
467
468
```
468
469
469
470
Giving it a type will compile, though:
@@ -472,7 +473,7 @@ Giving it a type will compile, though:
472
473
let x: int;
473
474
```
474
475
475
- Let's try it out. Change your ` src/hello_world .rs ` file to look like this:
476
+ Let's try it out. Change your ` src/main .rs ` file to look like this:
476
477
477
478
``` {rust}
478
479
fn main() {
@@ -487,8 +488,8 @@ but it will still print "Hello, world!":
487
488
488
489
``` {ignore,notrust}
489
490
Compiling hello_world v0.0.1 (file:///home/you/projects/hello_world)
490
- src/hello_world .rs:2:9: 2:10 warning: unused variable: `x`, #[warn(unused_variable)] on by default
491
- src/hello_world .rs:2 let x: int;
491
+ src/main .rs:2:9: 2:10 warning: unused variable: `x`, #[warn(unused_variable)] on by default
492
+ src/main .rs:2 let x: int;
492
493
^
493
494
```
494
495
@@ -509,13 +510,13 @@ And try to build it. You'll get an error:
509
510
``` {bash}
510
511
$ cargo build
511
512
Compiling hello_world v0.0.1 (file:///home/you/projects/hello_world)
512
- src/hello_world .rs:4:39: 4:40 error: use of possibly uninitialized variable: `x`
513
- src/hello_world .rs:4 println!("The value of x is: {}", x);
514
- ^
513
+ src/main .rs:4:39: 4:40 error: use of possibly uninitialized variable: `x`
514
+ src/main .rs:4 println!("The value of x is: {}", x);
515
+ ^
515
516
note: in expansion of format_args!
516
517
<std macros>:2:23: 2:77 note: expansion site
517
518
<std macros>:1:1: 3:2 note: in expansion of println!
518
- src/hello_world .rs:4:5: 4:42 note: expansion site
519
+ src/main .rs:4:5: 4:42 note: expansion site
519
520
error: aborting due to previous error
520
521
Could not compile `hello_world`.
521
522
```
0 commit comments