@@ -297,7 +297,7 @@ $ mv hello_world.rs src/hello_world.rs
297
297
```
298
298
299
299
Cargo 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
301
301
not related to your code. Cargo helps us keep our projects nice and tidy. A
302
302
place for everything, and everything in its place.
303
303
@@ -315,7 +315,7 @@ Put this inside:
315
315
[package]
316
316
317
317
name = "hello_world"
318
- version = "0.1.0 "
318
+ version = "0.0.1 "
319
319
authors = [ "Your name <[email protected] >" ]
320
320
321
321
[[bin]]
@@ -630,7 +630,7 @@ In Rust, however, using `let` to introduce a binding is _not_ an expression. The
630
630
following will produce a compile-time error:
631
631
632
632
``` {ignore}
633
- let x = (let y = 5i); // found `let` in ident position
633
+ let x = (let y = 5i); // expected identifier, found keyword `let`
634
634
```
635
635
636
636
The compiler is telling us here that it was expecting to see the beginning of
@@ -1743,7 +1743,7 @@ fn main() {
1743
1743
}
1744
1744
```
1745
1745
1746
- Sometimes, this makes things more readable. Sometimes, less. Use your judgement
1746
+ Sometimes, this makes things more readable. Sometimes, less. Use your judgment
1747
1747
here.
1748
1748
1749
1749
That's all you need to get basic input from the standard input! It's not too
@@ -1813,7 +1813,7 @@ Try it out:
1813
1813
1814
1814
``` {notrust,ignore}
1815
1815
$ 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)
1817
1817
Running `target/guessing_game`
1818
1818
Hello, world!
1819
1819
```
@@ -1959,7 +1959,7 @@ Try running our new program a few times:
1959
1959
1960
1960
``` {notrust,ignore}
1961
1961
$ 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)
1963
1963
Running `target/guessing_game`
1964
1964
Guess the number!
1965
1965
The secret number is: 7
@@ -2012,7 +2012,7 @@ And trying it out:
2012
2012
2013
2013
``` {notrust,ignore}
2014
2014
$ 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)
2016
2016
Running `target/guessing_game`
2017
2017
Guess the number!
2018
2018
The secret number is: 57
@@ -2283,7 +2283,7 @@ print an error message and return. Let's give this a shot:
2283
2283
2284
2284
``` {notrust,ignore}
2285
2285
$ 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)
2287
2287
Running `target/guessing_game`
2288
2288
Guess the number!
2289
2289
The secret number is: 17
@@ -2348,7 +2348,7 @@ Let's try it!
2348
2348
2349
2349
``` {notrust,ignore}
2350
2350
$ 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)
2352
2352
Running `target/guessing_game`
2353
2353
Guess the number!
2354
2354
The secret number is: 58
@@ -2425,7 +2425,7 @@ that `return`? If we give a non-number answer, we'll `return` and quit. Observe:
2425
2425
2426
2426
``` {notrust,ignore}
2427
2427
$ 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)
2429
2429
Running `target/guessing_game`
2430
2430
Guess the number!
2431
2431
The secret number is: 59
@@ -2557,7 +2557,7 @@ Now we should be good! Let's try:
2557
2557
2558
2558
``` {notrust,ignore}
2559
2559
$ 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)
2561
2561
Running `target/guessing_game`
2562
2562
Guess the number!
2563
2563
The secret number is: 61
@@ -2659,7 +2659,7 @@ modules, which can contain other modules, as deeply as you'd like.
2659
2659
Note that we haven't mentioned anything about files yet. Rust does not impose a
2660
2660
particular relationship between your filesystem structure and your module
2661
2661
structure. 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 .
2663
2663
2664
2664
Enough talk, let's build something! Let's make a new project called ` modules ` .
2665
2665
@@ -2670,10 +2670,10 @@ $ cargo new modules --bin
2670
2670
2671
2671
Let's double check our work by compiling:
2672
2672
2673
- ``` {bash,ignore }
2674
- $ cargo build
2673
+ ``` {bash,notrust }
2674
+ $ cargo run
2675
2675
Compiling modules v0.0.1 (file:///home/you/projects/modules)
2676
- $ ./ target/modules
2676
+ Running ` target/modules`
2677
2677
Hello, world!
2678
2678
```
2679
2679
@@ -3011,7 +3011,7 @@ markers.
3011
3011
Rust provides six attributes to indicate the stability level of various
3012
3012
parts of your library. The six levels are:
3013
3013
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
3015
3015
compatibility.
3016
3016
* experimental: This item was only recently introduced or is otherwise in a
3017
3017
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.
3300
3300
3301
3301
Rust can't find this function. That makes sense, as we didn't write it yet!
3302
3302
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.
3304
3304
This is also just good software design: as we mentioned before, it's a good idea
3305
3305
to put most of your functionality into a library crate, and have your executable
3306
3306
crate use that library. This allows for code re-use.
@@ -3511,7 +3511,7 @@ exporting the name again, somewhere else.
3511
3511
3512
3512
We've now covered the basics of testing. Rust's tools are primitive, but they
3513
3513
work 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
3515
3515
out.
3516
3516
3517
3517
# Pointers
@@ -3668,15 +3668,20 @@ because it's easy. And if you need precise control over when something is
3668
3668
deallocated, leaving it up to your runtime can make this difficult.
3669
3669
3670
3670
Rust 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:
3673
3674
3674
3675
1 . You control when that resource is deallocated.
3675
3676
2 . 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.
3680
3685
3681
3686
What's up with all this 'lending' and 'borrowing'? When you allocate memory,
3682
3687
you get a pointer to that memory. This pointer allows you to manipulate said
@@ -4063,7 +4068,7 @@ match x {
4063
4068
}
4064
4069
```
4065
4070
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:
4067
4072
4068
4073
``` {rust}
4069
4074
struct Point {
@@ -4223,7 +4228,7 @@ don't need to declare one. This is different from named functions, which
4223
4228
default to returning unit (` () ` ).
4224
4229
4225
4230
There'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
4227
4232
this:
4228
4233
4229
4234
``` {rust}
@@ -5494,7 +5499,7 @@ fn main() {
5494
5499
5495
5500
Whew! This isn't too terrible. You can see that we still ` let x = 5i ` ,
5496
5501
but 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
5498
5503
invoke the ` println_args ` function with the generated arguments.
5499
5504
5500
5505
This 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.
5510
5515
5511
5516
# Unsafe
5512
5517
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 ` .
5514
5519
There are two circumstances where Rust's safety provisions don't work well.
5515
5520
The first is when interfacing with C code, and the second is when building
5516
5521
certain kinds of abstractions.
0 commit comments