@@ -297,7 +297,7 @@ $ mv hello_world.rs src/hello_world.rs
297297```
298298
299299Cargo expects your source files to live inside a ` src ` directory. That leaves
300- the top level for other things, like READMEs, licence information, and anything
300+ the top level for other things, like READMEs, license information, and anything
301301not related to your code. Cargo helps us keep our projects nice and tidy. A
302302place for everything, and everything in its place.
303303
@@ -315,7 +315,7 @@ Put this inside:
315315[package]
316316
317317name = "hello_world"
318- version = "0.1.0 "
318+ version = "0.0.1 "
319319authors = [ "Your name <you@example.com>" ]
320320
321321[[bin]]
@@ -630,7 +630,7 @@ In Rust, however, using `let` to introduce a binding is _not_ an expression. The
630630following will produce a compile-time error:
631631
632632``` {ignore}
633- let x = (let y = 5i); // found `let` in ident position
633+ let x = (let y = 5i); // expected identifier, found keyword `let`
634634```
635635
636636The compiler is telling us here that it was expecting to see the beginning of
@@ -1743,7 +1743,7 @@ fn main() {
17431743}
17441744```
17451745
1746- Sometimes, this makes things more readable. Sometimes, less. Use your judgement
1746+ Sometimes, this makes things more readable. Sometimes, less. Use your judgment
17471747here.
17481748
17491749That's all you need to get basic input from the standard input! It's not too
@@ -1813,7 +1813,7 @@ Try it out:
18131813
18141814``` {notrust,ignore}
18151815$ cargo run
1816- Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
1816+ Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
18171817 Running `target/guessing_game`
18181818Hello, world!
18191819```
@@ -1959,7 +1959,7 @@ Try running our new program a few times:
19591959
19601960``` {notrust,ignore}
19611961$ cargo run
1962- Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
1962+ Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
19631963 Running `target/guessing_game`
19641964Guess the number!
19651965The secret number is: 7
@@ -2012,7 +2012,7 @@ And trying it out:
20122012
20132013``` {notrust,ignore}
20142014$ cargo run
2015- Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
2015+ Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
20162016 Running `target/guessing_game`
20172017Guess the number!
20182018The secret number is: 57
@@ -2283,7 +2283,7 @@ print an error message and return. Let's give this a shot:
22832283
22842284``` {notrust,ignore}
22852285$ cargo run
2286- Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
2286+ Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
22872287 Running `target/guessing_game`
22882288Guess the number!
22892289The secret number is: 17
@@ -2348,7 +2348,7 @@ Let's try it!
23482348
23492349``` {notrust,ignore}
23502350$ cargo run
2351- Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
2351+ Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
23522352 Running `target/guessing_game`
23532353Guess the number!
23542354The secret number is: 58
@@ -2425,7 +2425,7 @@ that `return`? If we give a non-number answer, we'll `return` and quit. Observe:
24252425
24262426``` {notrust,ignore}
24272427$ cargo run
2428- Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
2428+ Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
24292429 Running `target/guessing_game`
24302430Guess the number!
24312431The secret number is: 59
@@ -2557,7 +2557,7 @@ Now we should be good! Let's try:
25572557
25582558``` {notrust,ignore}
25592559$ cargo run
2560- Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
2560+ Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
25612561 Running `target/guessing_game`
25622562Guess the number!
25632563The secret number is: 61
@@ -2659,7 +2659,7 @@ modules, which can contain other modules, as deeply as you'd like.
26592659Note that we haven't mentioned anything about files yet. Rust does not impose a
26602660particular relationship between your filesystem structure and your module
26612661structure. That said, there is a conventional approach to how Rust looks for
2662- modules on the file system, but it's also overrideable .
2662+ modules on the file system, but it's also overridable .
26632663
26642664Enough talk, let's build something! Let's make a new project called ` modules ` .
26652665
@@ -2670,10 +2670,10 @@ $ cargo new modules --bin
26702670
26712671Let's double check our work by compiling:
26722672
2673- ``` {bash,ignore }
2674- $ cargo build
2673+ ``` {bash,notrust }
2674+ $ cargo run
26752675 Compiling modules v0.0.1 (file:///home/you/projects/modules)
2676- $ ./ target/modules
2676+ Running ` target/modules`
26772677Hello, world!
26782678```
26792679
@@ -3011,7 +3011,7 @@ markers.
30113011Rust provides six attributes to indicate the stability level of various
30123012parts of your library. The six levels are:
30133013
3014- * deprecated: this item should no longer be used. No guarantee of backwards
3014+ * deprecated: This item should no longer be used. No guarantee of backwards
30153015 compatibility.
30163016* experimental: This item was only recently introduced or is otherwise in a
30173017 state of flux. It may change significantly, or even be removed. No guarantee
@@ -3300,7 +3300,7 @@ To learn more, run the command again with --verbose.
33003300
33013301Rust can't find this function. That makes sense, as we didn't write it yet!
33023302
3303- In order to share this codes with our tests, we'll need to make a library crate.
3303+ In order to share this code with our tests, we'll need to make a library crate.
33043304This is also just good software design: as we mentioned before, it's a good idea
33053305to put most of your functionality into a library crate, and have your executable
33063306crate use that library. This allows for code re-use.
@@ -3511,7 +3511,7 @@ exporting the name again, somewhere else.
35113511
35123512We've now covered the basics of testing. Rust's tools are primitive, but they
35133513work well in the simple cases. There are some Rustaceans working on building
3514- more complicated frameworks on top of all of this, but thery 're just starting
3514+ more complicated frameworks on top of all of this, but they 're just starting
35153515out.
35163516
35173517# Pointers
@@ -3668,15 +3668,20 @@ because it's easy. And if you need precise control over when something is
36683668deallocated, leaving it up to your runtime can make this difficult.
36693669
36703670Rust chooses a different path, and that path is called ** ownership** . Any
3671- binding that creates a resource is the ** owner** of that resource. Being an
3672- owner gives you three privileges, with two restrictions:
3671+ binding that creates a resource is the ** owner** of that resource.
3672+
3673+ Being an owner affords you some privileges:
36733674
367436751 . You control when that resource is deallocated.
367536762 . You may lend that resource, immutably, to as many borrowers as you'd like.
3676- 3 . You may lend that resource, mutably, to a single borrower. ** BUT**
3677- 4 . Once you've done so, you may not also lend it out otherwise, mutably or
3678- immutably.
3679- 5 . You may not lend it out mutably if you're currently lending it to someone.
3677+ 3 . You may lend that resource, mutably, to a single borrower.
3678+
3679+ But it also comes with some restrictions:
3680+
3681+ 1 . If someone is borrowing your resource (either mutably or immutably), you may
3682+ not mutate the resource or mutably lend it to someone.
3683+ 2 . If someone is mutably borrowing your resource, you may not lend it out at
3684+ all (mutably or immutably) or access it in any way.
36803685
36813686What's up with all this 'lending' and 'borrowing'? When you allocate memory,
36823687you get a pointer to that memory. This pointer allows you to manipulate said
@@ -4063,7 +4068,7 @@ match x {
40634068}
40644069```
40654070
4066- If you have a struct, you can desugar it inside of a pattern:
4071+ If you have a struct, you can destructure it inside of a pattern:
40674072
40684073``` {rust}
40694074struct Point {
@@ -4223,7 +4228,7 @@ don't need to declare one. This is different from named functions, which
42234228default to returning unit (` () ` ).
42244229
42254230There's one big difference between a closure and named functions, and it's in
4226- the name: a function "closes over its environment." What's that mean? It means
4231+ the name: a closure "closes over its environment." What's that mean? It means
42274232this:
42284233
42294234``` {rust}
@@ -5494,7 +5499,7 @@ fn main() {
54945499
54955500Whew! This isn't too terrible. You can see that we still ` let x = 5i ` ,
54965501but then things get a little bit hairy. Three more bindings get set: a
5497- static format string, an argument vector, and the aruments . We then
5502+ static format string, an argument vector, and the arguments . We then
54985503invoke the ` println_args ` function with the generated arguments.
54995504
55005505This is the code (well, the full version) that Rust actually compiles. You can
@@ -5510,7 +5515,7 @@ Guide can help you if you want to write your own.
55105515
55115516# Unsafe
55125517
5513- Finally, there's one more concept that you should be aware in Rust : ` unsafe ` .
5518+ Finally, there's one more Rust concept that you should be aware of : ` unsafe ` .
55145519There are two circumstances where Rust's safety provisions don't work well.
55155520The first is when interfacing with C code, and the second is when building
55165521certain kinds of abstractions.
0 commit comments