Skip to content

Commit 0b5f794

Browse files
committed
Rollup merge of #30755 - datagrok:master, r=steveklabnik
I'm working my way through TRPL beginning at "Syntax and Semantics" as was recommended in a previous version. I'm expecting the chapter to incrementally build up my knowledge of the language section by section, assuming no prior Rust experience. So it was a bit of a speed-bump to encounter references and the vector type in a code example long before they had been defined and explained. Another commit in this PR tries to make consistent what is a "chapter" of TRPL versus a "section." Just a nit-pick, but not thinking about that stuff keeps my focus on the important material. My background: Python programmer since ~2000, with moderate exposure to C, C++, assembly, operating systems, and system architecture in university several years ago. For your kind consideration, feel welcome to use or drop or rework any part of this.
2 parents 27df1ec + fcc3563 commit 0b5f794

10 files changed

+41
-27
lines changed

src/doc/book/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Even then, Rust still allows precise control like a low-level language would.
1414

1515
[rust]: https://www.rust-lang.org
1616

17-
“The Rust Programming Language” is split into sections. This introduction
17+
“The Rust Programming Language” is split into chapters. This introduction
1818
is the first. After this:
1919

2020
* [Getting started][gs] - Set up your computer for Rust development.

src/doc/book/closures.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ different.
208208

209209
Rust’s implementation of closures is a bit different than other languages. They
210210
are effectively syntax sugar for traits. You’ll want to make sure to have read
211-
the [traits chapter][traits] before this one, as well as the chapter on [trait
211+
the [traits][traits] section before this one, as well as the section on [trait
212212
objects][trait-objects].
213213

214214
[traits]: traits.html

src/doc/book/effective-rust.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
So you’ve learned how to write some Rust code. But there’s a difference between
44
writing *any* Rust code and writing *good* Rust code.
55

6-
This section consists of relatively independent tutorials which show you how to
6+
This chapter consists of relatively independent tutorials which show you how to
77
take your Rust to the next level. Common patterns and standard library features
88
will be introduced. Read these sections in any order of your choosing.

src/doc/book/error-handling.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ errors in a particular way. Generally speaking, error handling is divided into
55
two broad categories: exceptions and return values. Rust opts for return
66
values.
77

8-
In this chapter, we intend to provide a comprehensive treatment of how to deal
8+
In this section, we intend to provide a comprehensive treatment of how to deal
99
with errors in Rust. More than that, we will attempt to introduce error handling
1010
one piece at a time so that you'll come away with a solid working knowledge of
1111
how everything fits together.
1212

1313
When done naïvely, error handling in Rust can be verbose and annoying. This
14-
chapter will explore those stumbling blocks and demonstrate how to use the
14+
section will explore those stumbling blocks and demonstrate how to use the
1515
standard library to make error handling concise and ergonomic.
1616

1717
# Table of Contents
1818

19-
This chapter is very long, mostly because we start at the very beginning with
19+
This section is very long, mostly because we start at the very beginning with
2020
sum types and combinators, and try to motivate the way Rust does error handling
2121
incrementally. As such, programmers with experience in other expressive type
2222
systems may want to jump around.
@@ -636,7 +636,7 @@ Thus far, we've looked at error handling where everything was either an
636636
`Option` and a `Result`? Or what if you have a `Result<T, Error1>` and a
637637
`Result<T, Error2>`? Handling *composition of distinct error types* is the next
638638
challenge in front of us, and it will be the major theme throughout the rest of
639-
this chapter.
639+
this section.
640640

641641
## Composing `Option` and `Result`
642642

@@ -648,7 +648,7 @@ Of course, in real code, things aren't always as clean. Sometimes you have a
648648
mix of `Option` and `Result` types. Must we resort to explicit case analysis,
649649
or can we continue using combinators?
650650

651-
For now, let's revisit one of the first examples in this chapter:
651+
For now, let's revisit one of the first examples in this section:
652652

653653
```rust,should_panic
654654
use std::env;
@@ -1319,7 +1319,7 @@ and [`cause`](../std/error/trait.Error.html#method.cause), but the
13191319
limitation remains: `Box<Error>` is opaque. (N.B. This isn't entirely
13201320
true because Rust does have runtime reflection, which is useful in
13211321
some scenarios that are [beyond the scope of this
1322-
chapter](https://crates.io/crates/error).)
1322+
section](https://crates.io/crates/error).)
13231323

13241324
It's time to revisit our custom `CliError` type and tie everything together.
13251325

@@ -1486,7 +1486,7 @@ and [`fmt::Result`](../std/fmt/type.Result.html).
14861486

14871487
# Case study: A program to read population data
14881488

1489-
This chapter was long, and depending on your background, it might be
1489+
This section was long, and depending on your background, it might be
14901490
rather dense. While there is plenty of example code to go along with
14911491
the prose, most of it was specifically designed to be pedagogical. So,
14921492
we're going to do something new: a case study.
@@ -1512,7 +1512,7 @@ and [`rustc-serialize`](https://crates.io/crates/rustc-serialize) crates.
15121512

15131513
We're not going to spend a lot of time on setting up a project with
15141514
Cargo because it is already covered well in [the Cargo
1515-
chapter](../book/hello-cargo.html) and [Cargo's documentation][14].
1515+
section](../book/hello-cargo.html) and [Cargo's documentation][14].
15161516

15171517
To get started from scratch, run `cargo new --bin city-pop` and make sure your
15181518
`Cargo.toml` looks something like this:
@@ -2108,7 +2108,7 @@ handling.
21082108

21092109
# The Short Story
21102110

2111-
Since this chapter is long, it is useful to have a quick summary for error
2111+
Since this section is long, it is useful to have a quick summary for error
21122112
handling in Rust. These are some good “rules of thumb." They are emphatically
21132113
*not* commandments. There are probably good reasons to break every one of these
21142114
heuristics!

src/doc/book/getting-started.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
% Getting Started
22

3-
This first section of the book will get us going with Rust and its tooling.
3+
This first chapter 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.
66

77
# Installing Rust
88

99
The first step to using Rust is to install it. Generally speaking, you’ll need
10-
an Internet connection to run the commands in this chapter, as we’ll be
10+
an Internet connection to run the commands in this section, as we’ll be
1111
downloading Rust from the internet.
1212

1313
We’ll be showing off a number of commands using a terminal, and those lines all

src/doc/book/guessing-game.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ prompt us to enter a guess. Upon entering our guess, it will tell us if we’re
77
too low or too high. Once we guess correctly, it will congratulate us. Sounds
88
good?
99

10-
Along the way, we’ll learn a little bit about Rust. The next section, ‘Syntax
10+
Along the way, we’ll learn a little bit about Rust. The next chapter, ‘Syntax
1111
and Semantics’, will dive deeper into each part.
1212

1313
# Set up

src/doc/book/learn-rust.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
% Learn Rust
22

3-
Welcome! This section has a few tutorials that teach you Rust through building
3+
Welcome! This chapter has a few tutorials that teach you Rust through building
44
projects. You’ll get a high-level overview, but we’ll skim over the details.
55

66
If you’d prefer a more ‘from the ground up’-style experience, check

src/doc/book/ownership.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,24 @@ fn foo() {
5151
}
5252
```
5353

54-
When `v` comes into scope, a new [`Vec<T>`][vect] is created. In this case, the
55-
vector also allocates space on [the heap][heap], for the three elements. When
56-
`v` goes out of scope at the end of `foo()`, Rust will clean up everything
57-
related to the vector, even the heap-allocated memory. This happens
58-
deterministically, at the end of the scope.
54+
When `v` comes into scope, a new [vector] is created, and it allocates space on
55+
[the heap][heap] for each of its elements. When `v` goes out of scope at the
56+
end of `foo()`, Rust will clean up everything related to the vector, even the
57+
heap-allocated memory. This happens deterministically, at the end of the scope.
5958

60-
[vect]: ../std/vec/struct.Vec.html
59+
We'll cover [vectors] in detail later in this chapter; we only use them
60+
here as an example of a type that allocates space on the heap at runtime. They
61+
behave like [arrays], except their size may change by `push()`ing more
62+
elements onto them.
63+
64+
Vectors have a [generic type][generics] `Vec<T>`, so in this example `v` will have type
65+
`Vec<i32>`. We'll cover generics in detail later in this chapter.
66+
67+
[arrays]: primitive-types.html#arrays
68+
[vectors]: vectors.html
6169
[heap]: the-stack-and-the-heap.html
6270
[bindings]: variable-bindings.html
71+
[generics]: generics.html
6372

6473
# Move semantics
6574

src/doc/book/primitive-types.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,11 @@ variable binding. Slices have a defined length, can be mutable or immutable.
167167
## Slicing syntax
168168

169169
You can use a combo of `&` and `[]` to create a slice from various things. The
170-
`&` indicates that slices are similar to references, and the `[]`s, with a
171-
range, let you define the length of the slice:
170+
`&` indicates that slices are similar to [references], which we will cover in
171+
detail later in this section. The `[]`s, with a range, let you define the
172+
length of the slice:
173+
174+
[references]: references-and-borrowing.html
172175

173176
```rust
174177
let a = [0, 1, 2, 3, 4];
@@ -189,11 +192,13 @@ documentation][slice].
189192
# `str`
190193

191194
Rust’s `str` type is the most primitive string type. As an [unsized type][dst],
192-
it’s not very useful by itself, but becomes useful when placed behind a reference,
193-
like [`&str`][strings]. As such, we’ll just leave it at that.
195+
it’s not very useful by itself, but becomes useful when placed behind a
196+
reference, like `&str`. We'll elaborate further when we cover
197+
[Strings][strings] and [references].
194198

195199
[dst]: unsized-types.html
196200
[strings]: strings.html
201+
[references]: references-and-borrowing.html
197202

198203
You can find more documentation for `str` [in the standard library
199204
documentation][str].

src/doc/book/syntax-and-semantics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
% Syntax and Semantics
22

3-
This section breaks Rust down into small chunks, one for each concept.
3+
This chapter breaks Rust down into small chunks, one for each concept.
44

55
If you’d like to learn Rust from the bottom up, reading this in order is a
66
great way to do that.

0 commit comments

Comments
 (0)