Skip to content

Commit 8091cb1

Browse files
committed
Auto merge of #28930 - steveklabnik:update_pr, r=steveklabnik
#27813 (comment)
2 parents 39376de + 22fbbd4 commit 8091cb1

File tree

5 files changed

+158
-154
lines changed

5 files changed

+158
-154
lines changed

src/doc/trpl/README.md

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ requirements, and writing low-level code, like device drivers and operating
99
systems. It improves on current languages targeting this space by having a
1010
number of compile-time safety checks that produce no runtime overhead, while
1111
eliminating all data races. Rust also aims to achieve ‘zero-cost abstractions’
12-
even though some of these abstractions feel like those of a high-level
13-
language. Even then, Rust still allows precise control like a low-level
14-
language would.
12+
even though some of these abstractions feel like those of a high-level language.
13+
Even then, Rust still allows precise control like a low-level language would.
1514

1615
[rust]: https://www.rust-lang.org
1716

@@ -34,10 +33,10 @@ is the first. After this:
3433
[gl]: glossary.html
3534
[bi]: bibliography.html
3635

37-
After reading this introduction, you’ll want to dive into either ‘Learn Rust’
38-
or ‘Syntax and Semantics’, depending on your preference: ‘Learn Rust’ if you
39-
want to dive in with a project, or ‘Syntax and Semantics’ if you prefer to
40-
start small, and learn a single concept thoroughly before moving onto the next.
36+
After reading this introduction, you’ll want to dive into either ‘Learn Rust’ or
37+
‘Syntax and Semantics’, depending on your preference: ‘Learn Rust’ if you want
38+
to dive in with a project, or ‘Syntax and Semantics’ if you prefer to start
39+
small, and learn a single concept thoroughly before moving onto the next.
4140
Copious cross-linking connects these parts together.
4241

4342
### Contributing
@@ -76,11 +75,11 @@ type inference to balance out the power of static typing with the verbosity of
7675
annotating types.
7776

7877
Rust prefers stack allocation to heap allocation: `x` is placed directly on the
79-
stack. However, the `Vec<T>` type allocates space for the elements of the
80-
vector on the heap. If you’re not familiar with this distinction, you can
81-
ignore it for now, or check out [‘The Stack and the Heap’][heap]. As a systems
82-
programming language, Rust gives you the ability to control how your memory is
83-
allocated, but when we’re getting started, it’s less of a big deal.
78+
stack. However, the `Vec<T>` type allocates space for the elements of the vector
79+
on the heap. If you’re not familiar with this distinction, you can ignore it for
80+
now, or check out [‘The Stack and the Heap’][heap]. As a systems programming
81+
language, Rust gives us the ability to control how our memory is allocated, but
82+
when we’re getting started, it’s less of a big deal.
8483

8584
[var]: variable-bindings.html
8685
[macro]: macros.html
@@ -90,10 +89,10 @@ Earlier, we mentioned that ‘ownership’ is the key new concept in Rust. In Ru
9089
parlance, `x` is said to ‘own’ the vector. This means that when `x` goes out of
9190
scope, the vector’s memory will be de-allocated. This is done deterministically
9291
by the Rust compiler, rather than through a mechanism such as a garbage
93-
collector. In other words, in Rust, you don’t call functions like `malloc` and
94-
`free` yourself: the compiler statically determines when you need to allocate
95-
or deallocate memory, and inserts those calls itself. To err is to be human,
96-
but compilers never forget.
92+
collector. In other words, in Rust, we don’t call functions like `malloc` and
93+
`free` ourselves: the compiler statically determines when we need to allocate or
94+
deallocate memory, and inserts those calls itself. To err is to be human, but
95+
compilers never forget.
9796

9897
Let’s add another line to our example:
9998

@@ -105,13 +104,13 @@ fn main() {
105104
}
106105
```
107106

108-
We’ve introduced another binding, `y`. In this case, `y` is a ‘reference’ to
109-
the first element of the vector. Rust’s references are similar to pointers in
110-
other languages, but with additional compile-time safety checks. References
111-
interact with the ownership system by [‘borrowing’][borrowing] what they point
112-
to, rather than owning it. The difference is, when the reference goes out of
113-
scope, it will not deallocate the underlying memory. If it did, we’d
114-
de-allocate twice, which is bad!
107+
We’ve introduced another binding, `y`. In this case, `y` is a ‘reference’ to the
108+
first element of the vector. Rust’s references are similar to pointers in other
109+
languages, but with additional compile-time safety checks. References interact
110+
with the ownership system by [‘borrowing’][borrowing] what they point to, rather
111+
than owning it. The difference is, when the reference goes out of scope, it
112+
won't deallocate the underlying memory. If it did, we’d de-allocate twice, which
113+
is bad!
115114

116115
[borrowing]: references-and-borrowing.html
117116

@@ -147,7 +146,7 @@ fn main() {
147146

148147
Whew! The Rust compiler gives quite detailed errors at times, and this is one
149148
of those times. As the error explains, while we made our binding mutable, we
150-
still cannot call `push`. This is because we already have a reference to an
149+
still can't call `push`. This is because we already have a reference to an
151150
element of the vector, `y`. Mutating something while another reference exists
152151
is dangerous, because we may invalidate the reference. In this specific case,
153152
when we create the vector, we may have only allocated space for two elements.

src/doc/trpl/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
% Getting Started
22

3-
This first section of the book will get you going with Rust and its tooling.
3+
This first section of the book will get us going with Rust and its tooling.
44
First, we’ll install Rust. Then, the classic ‘Hello World’ program. Finally,
55
we’ll talk about Cargo, Rust’s build system and package manager.

src/doc/trpl/hello-cargo.md

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ so it is assumed that Rust projects will use Cargo from the beginning.
77

88
[cratesio]: http://doc.crates.io
99

10-
Cargo manages three things: building your code, downloading the dependencies
11-
your code needs, and building those dependencies. At first, your program doesn’t
12-
have any dependencies, so we’ll only be using the first part of its
13-
functionality. Eventually, we’ll add more. Since we started off by using Cargo,
14-
it'll be easy to add later.
10+
Cargo manages three things: building our code, downloading the dependencies our
11+
code needs, and building those dependencies. At first, our program doesn’t have
12+
any dependencies, so we’ll only be using the first part of its functionality.
13+
Eventually, we’ll add more. Since we started off by using Cargo, it'll be easy
14+
to add later.
1515

16-
If we installed Rust via the official installers we will also have Cargo. If we
17-
installed Rust some other way, we may want to [check the Cargo
18-
README][cargoreadme] for specific instructions about installing it.
16+
If you installed Rust via the official installers you will also have Cargo. If
17+
you installed Rust some other way, you may want to
18+
[check the Cargo README][cargoreadme] for specific instructions about installing
19+
it.
1920

2021
[cargoreadme]: https://github.com/rust-lang/cargo#installing-cargo-from-nightlies
2122

@@ -30,29 +31,29 @@ old executable (`main.exe` on Windows, `main` everywhere else). Let's do that pa
3031
```bash
3132
$ mkdir src
3233
$ mv main.rs src/main.rs
33-
$ rm main # or main.exe on Windows
34+
$ rm main # or 'rm main.exe' on Windows
3435
```
3536

36-
Note that since we're creating an executable, we retain `main.rs` as the source
37-
filename. If we want to make a library instead, we should use `lib.rs`. This
38-
convention is used by Cargo to successfully compile our projects, but it can be
39-
overridden if we wish. Custom file locations for the entry point can be
40-
specified with a [`[lib]` or `[[bin]]`][crates-custom] key in the TOML file.
37+
> Note: since we're creating an executable, we retain `main.rs` as the source
38+
> filename. If we want to make a library instead, we should use `lib.rs`. This
39+
> convention is used by Cargo to successfully compile our projects, but it can
40+
> be overridden if we wish. Custom file locations for the entry point can be
41+
> specified with a [`[lib]` or `[[bin]]`][crates-custom] key in the TOML file.
4142
4243
[crates-custom]: http://doc.crates.io/manifest.html#configuring-a-target
4344

44-
Cargo expects your source files to live inside a `src` directory. That leaves
45-
the top level for other things, like READMEs, license information, and anything
46-
not related to your code. Cargo helps us keep our projects nice and tidy. A
47-
place for everything, and everything in its place.
45+
Cargo expects our source files to live inside a `src` directory. That leaves the
46+
top level for other things, like READMEs, license information, and anything not
47+
related to our code. Cargo helps us keep our projects nice and tidy. A place for
48+
everything, and everything in its place.
4849

4950
Next, our configuration file:
5051

5152
```bash
52-
$ editor Cargo.toml
53+
$ editor Cargo.toml # or 'notepad Cargo.toml' on Windows
5354
```
5455

55-
Make sure to get this name right: you need the capital `C`!
56+
Make sure to get this name right: we need the capital `C`!
5657

5758
Put this inside:
5859

@@ -109,8 +110,8 @@ about the future: when our project gets more complex, we need to do more
109110
things to get all of the parts to properly compile. With Cargo, as our project
110111
grows, we can just run `cargo build`, and it’ll work the right way.
111112

112-
When your project is finally ready for release, you can use
113-
`cargo build --release` to compile your project with optimizations.
113+
When our project is finally ready for release, we can use `cargo build
114+
--release` to compile our project with optimizations.
114115

115116
You'll also notice that Cargo has created a new file: `Cargo.lock`.
116117

@@ -120,14 +121,14 @@ name = "hello_world"
120121
version = "0.0.1"
121122
```
122123

123-
The `Cargo.lock` file is used by Cargo to keep track of dependencies in your application.
124-
Right now, we don’t have any, so it’s a bit sparse. You won't ever need
125-
to touch this file yourself, just let Cargo handle it.
124+
The `Cargo.lock` file is used by Cargo to keep track of dependencies in our
125+
application. Right now, we don’t have any, so it’s a bit sparse. We won't ever
126+
need to touch this file ourselves, just let Cargo handle it.
126127

127128
That’s it! We’ve successfully built `hello_world` with Cargo. Even though our
128-
program is simple, it’s using much of the real tooling that you’ll use for the
129-
rest of your Rust career. You can expect to do this to get started with
130-
virtually all Rust projects:
129+
program is simple, it’s using much of the real tooling that we’ll use for the
130+
rest of our Rust career. We can expect to do this to get started with virtually
131+
all Rust projects:
131132

132133
```bash
133134
$ git clone someurl.com/foo
@@ -137,17 +138,19 @@ $ cargo build
137138

138139
## A New Project
139140

140-
You don’t have to go through this whole process every time you want to start a
141-
new project! Cargo has the ability to make a bare-bones project directory in
142-
which you can start developing right away.
141+
We don’t have to go through this whole process every time we want to start a new
142+
project! Cargo has the ability to make a bare-bones project directory in which
143+
we can start developing right away.
143144

144-
To start a new project with Cargo, use `cargo new`:
145+
To start a new project with Cargo, we use `cargo new`:
145146

146147
```bash
147148
$ cargo new hello_world --bin
148149
```
149150

150-
We’re passing `--bin` because our goal is to get straight to making an executable application, as opposed to a library. Executables are often called ‘binaries.’ (as in `/usr/bin`, if you’re on a Unix system)
151+
We’re passing `--bin` because our goal is to get straight to making an
152+
executable application, as opposed to a library. Executables are often called
153+
‘binaries.’ (as in `/usr/bin`, if we’re on a Unix system)
151154

152155
Let's check out what Cargo has generated for us:
153156

@@ -162,7 +165,7 @@ $ tree .
162165
1 directory, 2 files
163166
```
164167

165-
If you don't have the `tree` command, you can probably get it from your
168+
If we don't have the `tree` command, we can probably get it from our
166169
distribution’s package manager. It’s not necessary, but it’s certainly useful.
167170

168171
This is all we need to get started. First, let’s check out `Cargo.toml`:
@@ -176,7 +179,7 @@ authors = ["Your Name <[email protected]>"]
176179
```
177180

178181
Cargo has populated this file with reasonable defaults based off the arguments
179-
you gave it and your `git` global configuration. You may notice that Cargo has
182+
we gave it and our `git` global configuration. You may notice that Cargo has
180183
also initialized the `hello_world` directory as a `git` repository.
181184

182185
Here’s what’s in `src/main.rs`:
@@ -187,20 +190,21 @@ fn main() {
187190
}
188191
```
189192

190-
Cargo has generated a "Hello World!" for us, and you’re ready to start coding! Cargo
191-
has its own [guide][guide] which covers Cargo’s features in much more depth.
193+
Cargo has generated a "Hello World!" for us, and we’re ready to start coding!
194+
Cargo has its own [guide][guide] which covers Cargo’s features in much more
195+
depth.
192196

193197
[guide]: http://doc.crates.io/guide.html
194198

195-
Now that you’ve got the tools down, let’s actually learn more about the Rust
196-
language itself. These are the basics that will serve you well through the rest
197-
of your time with Rust.
199+
Now that we’ve got the tools down, let’s actually learn more about the Rust
200+
language itself. These are the basics that will serve us well through the rest
201+
of our time with Rust.
198202

199203
You have two options: Dive into a project with ‘[Learn Rust][learnrust]’, or
200-
start from the bottom and work your way up with[Syntax and
201-
Semantics][syntax]’. More experienced systems programmers will probably prefer
202-
‘Learn Rust’, while those from dynamic backgrounds may enjoy either. Different
203-
people learn differently! Choose whatever’s right for you.
204+
start from the bottom and work your way up with
205+
[Syntax and Semantics][syntax]’. More experienced systems programmers will
206+
probably prefer ‘Learn Rust’, while those from dynamic backgrounds may enjoy
207+
either. Different people learn differently! Choose whatever’s right for you.
204208

205209
[learnrust]: learn-rust.html
206210
[syntax]: syntax-and-semantics.html

0 commit comments

Comments
 (0)