Skip to content

Commit 9205d74

Browse files
committed
auto merge of #20782 : iKevinY/rust/trpl-formatting, r=steveklabnik
Here's my PR for the changes discussed in #19823. I decided to leave `_these_` types of italics the way there were because it differentiates the use of italics for emphasis from `*key term*` italics. Otherwise, bolded terms have been changed to italics, and single and double quotes have been changed appropriately, depending on their context (my judgement may not be the best, though). r? @steveklabnik (congratulations on #19897 being finalized and merged, by the way!)
2 parents 14f9d1f + 8f61814 commit 9205d74

29 files changed

+139
-139
lines changed

src/doc/trpl/arrays-vectors-and-slices.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
% Arrays, Vectors, and Slices
22

33
Like many programming languages, Rust has list types to represent a sequence of
4-
things. The most basic is the **array**, a fixed-size list of elements of the
4+
things. The most basic is the *array*, a fixed-size list of elements of the
55
same type. By default, arrays are immutable.
66

77
```{rust}
@@ -32,7 +32,7 @@ for e in a.iter() {
3232
}
3333
```
3434

35-
You can access a particular element of an array with **subscript notation**:
35+
You can access a particular element of an array with *subscript notation*:
3636

3737
```{rust}
3838
let names = ["Graydon", "Brian", "Niko"]; // names: [&str; 3]
@@ -47,7 +47,7 @@ array, you will get an error: array access is bounds-checked at run-time. Such
4747
errant access is the source of many bugs in other systems programming
4848
languages.
4949

50-
A **vector** is a dynamic or "growable" array, implemented as the standard
50+
A *vector* is a dynamic or "growable" array, implemented as the standard
5151
library type [`Vec<T>`](../std/vec/) (we'll talk about what the `<T>` means
5252
later). Vectors are to arrays what `String` is to `&str`. You can create them
5353
with the `vec!` macro:
@@ -73,7 +73,7 @@ println!("The length of nums is now {}", nums.len()); // Prints 4
7373

7474
Vectors have many more useful methods.
7575

76-
A **slice** is a reference to (or "view" into) an array. They are useful for
76+
A *slice* is a reference to (or "view" into) an array. They are useful for
7777
allowing safe, efficient access to a portion of an array without copying. For
7878
example, you might want to reference just one line of a file read into memory.
7979
By nature, a slice is not created directly, but from an existing variable.

src/doc/trpl/closures.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
So far, we've made lots of functions in Rust, but we've given them all names.
44
Rust also allows us to create anonymous functions. Rust's anonymous
5-
functions are called **closure**s. By themselves, closures aren't all that
5+
functions are called *closures*. By themselves, closures aren't all that
66
interesting, but when you combine them with functions that take closures as
77
arguments, really powerful things are possible.
88

@@ -61,7 +61,7 @@ fn main() {
6161

6262
## Moving closures
6363

64-
Rust has a second type of closure, called a **moving closure**. Moving
64+
Rust has a second type of closure, called a *moving closure*. Moving
6565
closures are indicated using the `move` keyword (e.g., `move || x *
6666
x`). The difference between a moving closure and an ordinary closure
6767
is that a moving closure always takes ownership of all variables that

src/doc/trpl/comments.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Now that we have some functions, it's a good idea to learn about comments.
44
Comments are notes that you leave to other programmers to help explain things
55
about your code. The compiler mostly ignores them.
66

7-
Rust has two kinds of comments that you should care about: **line comment**s
8-
and **doc comment**s.
7+
Rust has two kinds of comments that you should care about: *line comments*
8+
and *doc comments*.
99

1010
```{rust}
1111
// Line comments are anything after '//' and extend to the end of the line.

src/doc/trpl/compound-data-types.md

+13-14
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ strings, but next, let's talk about some more complicated ways of storing data.
66

77
## Tuples
88

9-
The first compound data type we're going to talk about are called **tuple**s.
9+
The first compound data type we're going to talk about are called *tuples*.
1010
Tuples are an ordered list of a fixed size. Like this:
1111

1212
```rust
@@ -25,10 +25,10 @@ position having a type name rather than the value. Careful readers will also
2525
note that tuples are heterogeneous: we have an `i32` and a `&str` in this tuple.
2626
You haven't seen `&str` as a type before, and we'll discuss the details of
2727
strings later. In systems programming languages, strings are a bit more complex
28-
than in other languages. For now, just read `&str` as "a string slice," and
28+
than in other languages. For now, just read `&str` as a *string slice*, and
2929
we'll learn more soon.
3030

31-
You can access the fields in a tuple through a **destructuring let**. Here's
31+
You can access the fields in a tuple through a *destructuring let*. Here's
3232
an example:
3333

3434
```rust
@@ -40,8 +40,8 @@ println!("x is {}", x);
4040
Remember before when I said the left-hand side of a `let` statement was more
4141
powerful than just assigning a binding? Here we are. We can put a pattern on
4242
the left-hand side of the `let`, and if it matches up to the right-hand side,
43-
we can assign multiple bindings at once. In this case, `let` 'destructures,'
44-
or 'breaks up,' the tuple, and assigns the bits to three bindings.
43+
we can assign multiple bindings at once. In this case, `let` "destructures,"
44+
or "breaks up," the tuple, and assigns the bits to three bindings.
4545

4646
This pattern is very powerful, and we'll see it repeated more later.
4747

@@ -83,18 +83,18 @@ fn main() {
8383
}
8484
```
8585

86-
Even though Rust functions can only return one value, a tuple _is_ one value,
87-
that happens to be made up of more than one value. You can also see in this example how you
88-
can destructure a pattern returned by a function, as well.
86+
Even though Rust functions can only return one value, a tuple *is* one value,
87+
that happens to be made up of more than one value. You can also see in this
88+
example how you can destructure a pattern returned by a function, as well.
8989

9090
Tuples are a very simple data structure, and so are not often what you want.
9191
Let's move on to their bigger sibling, structs.
9292

9393
## Structs
9494

95-
A struct is another form of a 'record type,' just like a tuple. There's a
95+
A struct is another form of a *record type*, just like a tuple. There's a
9696
difference: structs give each element that they contain a name, called a
97-
'field' or a 'member.' Check it out:
97+
*field* or a *member*. Check it out:
9898

9999
```rust
100100
struct Point {
@@ -143,8 +143,7 @@ This will print `The point is at (5, 0)`.
143143
## Tuple Structs and Newtypes
144144

145145
Rust has another data type that's like a hybrid between a tuple and a struct,
146-
called a **tuple struct**. Tuple structs do have a name, but their fields
147-
don't:
146+
called a *tuple struct*. Tuple structs do have a name, but their fields don't:
148147

149148

150149
```{rust}
@@ -182,7 +181,7 @@ Now, we have actual names, rather than positions. Good names are important,
182181
and with a struct, we have actual names.
183182

184183
There _is_ one case when a tuple struct is very useful, though, and that's a
185-
tuple struct with only one element. We call this a 'newtype,' because it lets
184+
tuple struct with only one element. We call this a *newtype*, because it lets
186185
you create a new type that's a synonym for another one:
187186

188187
```{rust}
@@ -199,7 +198,7 @@ destructuring `let`.
199198

200199
## Enums
201200

202-
Finally, Rust has a "sum type", an **enum**. Enums are an incredibly useful
201+
Finally, Rust has a "sum type", an *enum*. Enums are an incredibly useful
203202
feature of Rust, and are used throughout the standard library. This is an enum
204203
that is provided by the Rust standard library:
205204

src/doc/trpl/crates-and-modules.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ these kinds of things, Rust has a module system.
88

99
# Basic terminology: Crates and Modules
1010

11-
Rust has two distinct terms that relate to the module system: "crate" and
12-
"module." A crate is synonymous with a 'library' or 'package' in other
11+
Rust has two distinct terms that relate to the module system: *crate* and
12+
*module*. A crate is synonymous with a *library* or *package* in other
1313
languages. Hence "Cargo" as the name of Rust's package management tool: you
1414
ship your crates to others with Cargo. Crates can produce an executable or a
1515
shared library, depending on the project.
1616

17-
Each crate has an implicit "root module" that contains the code for that crate.
17+
Each crate has an implicit *root module* that contains the code for that crate.
1818
You can then define a tree of sub-modules under that root module. Modules allow
1919
you to partition your code within the crate itself.
2020

21-
As an example, let's make a "phrases" crate, which will give us various phrases
21+
As an example, let's make a *phrases* crate, which will give us various phrases
2222
in different languages. To keep things simple, we'll stick to "greetings" and
2323
"farewells" as two kinds of phrases, and use English and Japanese (日本語) as
2424
two languages for those phrases to be in. We'll use this module layout:
@@ -45,7 +45,7 @@ two languages for those phrases to be in. We'll use this module layout:
4545

4646
In this example, `phrases` is the name of our crate. All of the rest are
4747
modules. You can see that they form a tree, branching out from the crate
48-
"root", which is the root of the tree: `phrases` itself.
48+
*root*, which is the root of the tree: `phrases` itself.
4949

5050
Now that we have a plan, let's define these modules in code. To start,
5151
generate a new crate with Cargo:

src/doc/trpl/error-handling.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ how to handle each. Then, we'll discuss upgrading failures to panics.
1616
# Failure vs. Panic
1717

1818
Rust uses two terms to differentiate between two forms of error: failure, and
19-
panic. A **failure** is an error that can be recovered from in some way. A
20-
**panic** is an error that cannot be recovered from.
19+
panic. A *failure* is an error that can be recovered from in some way. A
20+
*panic* is an error that cannot be recovered from.
2121

22-
What do we mean by 'recover'? Well, in most cases, the possibility of an error
22+
What do we mean by "recover"? Well, in most cases, the possibility of an error
2323
is expected. For example, consider the `from_str` function:
2424

2525
```{rust,ignore}
@@ -35,7 +35,7 @@ from_str("hello5world");
3535
```
3636

3737
This won't work. So we know that this function will only work properly for some
38-
inputs. It's expected behavior. We call this kind of error 'failure.'
38+
inputs. It's expected behavior. We call this kind of error a *failure*.
3939

4040
On the other hand, sometimes, there are errors that are unexpected, or which
4141
we cannot recover from. A classic example is an `assert!`:
@@ -46,7 +46,7 @@ assert!(x == 5);
4646

4747
We use `assert!` to declare that something is true. If it's not true, something
4848
is very wrong. Wrong enough that we can't continue with things in the current
49-
state. Another example is using the `unreachable!()` macro
49+
state. Another example is using the `unreachable!()` macro:
5050

5151
```{rust,ignore}
5252
enum Event {
@@ -114,7 +114,7 @@ fn main() {
114114

115115
We shouldn't ever hit the `_` case, so we use the `unreachable!()` macro to
116116
indicate this. `unreachable!()` gives a different kind of error than `Result`.
117-
Rust calls these sorts of errors 'panics.'
117+
Rust calls these sorts of errors *panics*.
118118

119119
# Handling errors with `Option` and `Result`
120120

src/doc/trpl/ffi.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ GitHub](https://github.com/thestinger/rust-snappy).
166166

167167
# Stack management
168168

169-
Rust tasks by default run on a "large stack". This is actually implemented as a
169+
Rust tasks by default run on a *large stack*. This is actually implemented as a
170170
reserving a large segment of the address space and then lazily mapping in pages
171171
as they are needed. When calling an external C function, the code is invoked on
172172
the same stack as the rust stack. This means that there is no extra

src/doc/trpl/functions.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn main() {
88
```
99

1010
This is the simplest possible function declaration. As we mentioned before,
11-
`fn` says 'this is a function,' followed by the name, some parentheses because
11+
`fn` says "this is a function," followed by the name, some parentheses because
1212
this function takes no arguments, and then some curly braces to indicate the
1313
body. Here's a function named `foo`:
1414

@@ -86,7 +86,7 @@ fn add_one(x: i32) -> i32 {
8686
```
8787

8888
Rust functions return exactly one value, and you declare the type after an
89-
'arrow', which is a dash (`-`) followed by a greater-than sign (`>`).
89+
"arrow," which is a dash (`-`) followed by a greater-than sign (`>`).
9090

9191
You'll note the lack of a semicolon here. If we added it in:
9292

src/doc/trpl/generics.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ enum OptionalFloat64 {
2020
```
2121

2222
This is really unfortunate. Luckily, Rust has a feature that gives us a better
23-
way: generics. Generics are called **parametric polymorphism** in type theory,
24-
which means that they are types or functions that have multiple forms ("poly"
25-
is multiple, "morph" is form) over a given parameter ("parametric").
23+
way: generics. Generics are called *parametric polymorphism* in type theory,
24+
which means that they are types or functions that have multiple forms (*poly*
25+
is multiple, *morph* is form) over a given parameter (*parametric*).
2626

2727
Anyway, enough with type theory declarations, let's check out the generic form
2828
of `OptionalInt`. It is actually provided by Rust itself, and looks like this:
@@ -150,7 +150,7 @@ fn inverse32(x: f32) -> Result<f32, String> {
150150
}
151151
```
152152

153-
Bummer. What we need is a **generic function**. Luckily, we can write one!
153+
Bummer. What we need is a *generic function*. Luckily, we can write one!
154154
However, it won't _quite_ work yet. Before we get into that, let's talk syntax.
155155
A generic version of `inverse` would look something like this:
156156

src/doc/trpl/guessing-game.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Enter the docs. Rust has a page specifically to document the standard library.
111111
You can find that page [here](../std/index.html). There's a lot of information on
112112
that page, but the best part is the search bar. Right up at the top, there's
113113
a box that you can enter in a search term. The search is pretty primitive
114-
right now, but is getting better all the time. If you type 'random' in that
114+
right now, but is getting better all the time. If you type "random" in that
115115
box, the page will update to [this one](../std/index.html?search=random). The very
116116
first result is a link to [`std::rand::random`](../std/rand/fn.random.html). If we
117117
click on that result, we'll be taken to its documentation page.
@@ -147,7 +147,7 @@ explained. We then added in a `let` expression to create a variable binding
147147
named `secret_number`, and we printed out its result.
148148

149149
Also, you may wonder why we are using `%` on the result of `rand::random()`.
150-
This operator is called 'modulo', and it returns the remainder of a division.
150+
This operator is called *modulo*, and it returns the remainder of a division.
151151
By taking the modulo of the result of `rand::random()`, we're limiting the
152152
values to be between 0 and 99. Then, we add one to the result, making it from 1
153153
to 100. Using modulo can give you a very, very small bias in the result, but
@@ -608,8 +608,8 @@ out that I guessed 76. Run the program a few times, and verify that guessing
608608
the number works, as well as guessing a number too small.
609609
610610
The Rust compiler helped us out quite a bit there! This technique is called
611-
"lean on the compiler", and it's often useful when working on some code. Let
612-
the error messages help guide you towards the correct types.
611+
"leaning on the compiler", and it's often useful when working on some code.
612+
Let the error messages help guide you towards the correct types.
613613
614614
Now we've got most of the game working, but we can only make one guess. Let's
615615
change that by adding loops!

src/doc/trpl/hello-cargo.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ it explain itself to you:
6666
6767
TOML is very similar to INI, but with some extra goodies.
6868

69-
Anyway, there are two **table**s in this file: `package` and `bin`. The first
69+
Anyway, there are two *tables* in this file: `package` and `bin`. The first
7070
tells Cargo metadata about your package. The second tells Cargo that we're
7171
interested in building a binary, not a library (though we could do both!), as
7272
well as what it is named.

src/doc/trpl/hello-world.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn main() {
6767
}
6868
```
6969

70-
These lines define a **function** in Rust. The `main` function is special:
70+
These lines define a *function* in Rust. The `main` function is special:
7171
it's the beginning of every Rust program. The first line says "I'm declaring a
7272
function named `main`, which takes no arguments and returns nothing." If there
7373
were arguments, they would go inside the parentheses (`(` and `)`), and because
@@ -91,7 +91,7 @@ spaces, not tabs. Please configure your editor of choice to insert four spaces
9191
with the tab key. We provide some [sample configurations for various
9292
editors](https://github.com/rust-lang/rust/tree/master/src/etc).
9393

94-
The second point is the `println!()` part. This is calling a Rust **macro**,
94+
The second point is the `println!()` part. This is calling a Rust *macro*,
9595
which is how metaprogramming is done in Rust. If it were a function instead, it
9696
would look like this: `println()`. For our purposes, we don't need to worry
9797
about this difference. Just know that sometimes, you'll see a `!`, and that
@@ -102,19 +102,19 @@ last thing to mention: Rust's macros are significantly different from C macros,
102102
if you've used those. Don't be scared of using macros. We'll get to the details
103103
eventually, you'll just have to trust us for now.
104104

105-
Next, `"Hello, world!"` is a **string**. Strings are a surprisingly complicated
106-
topic in a systems programming language, and this is a **statically allocated**
105+
Next, `"Hello, world!"` is a *string*. Strings are a surprisingly complicated
106+
topic in a systems programming language, and this is a *statically allocated*
107107
string. We will talk more about different kinds of allocation later. We pass
108108
this string as an argument to `println!`, which prints the string to the
109109
screen. Easy enough!
110110

111-
Finally, the line ends with a semicolon (`;`). Rust is an **expression
112-
oriented** language, which means that most things are expressions. The `;` is
111+
Finally, the line ends with a semicolon (`;`). Rust is an *expression
112+
oriented* language, which means that most things are expressions. The `;` is
113113
used to indicate that this expression is over, and the next one is ready to
114114
begin. Most lines of Rust code end with a `;`. We will cover this in-depth
115115
later in the guide.
116116

117-
Finally, actually **compiling** and **running** our program. We can compile
117+
Finally, actually *compiling* and *running* our program. We can compile
118118
with our compiler, `rustc`, by passing it the name of our source file:
119119

120120
```{bash}
@@ -147,7 +147,7 @@ This prints out our `Hello, world!` text to our terminal.
147147

148148
If you come from a dynamically typed language like Ruby, Python, or JavaScript,
149149
you may not be used to these two steps being separate. Rust is an
150-
**ahead-of-time compiled language**, which means that you can compile a
150+
*ahead-of-time compiled language*, which means that you can compile a
151151
program, give it to someone else, and they don't need to have Rust installed.
152152
If you give someone a `.rb` or `.py` or `.js` file, they need to have
153153
Ruby/Python/JavaScript installed, but you just need one command to both compile

0 commit comments

Comments
 (0)