@@ -6,7 +6,7 @@ strings, but next, let's talk about some more complicated ways of storing data.
6
6
7
7
## Tuples
8
8
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 * .
10
10
Tuples are an ordered list of a fixed size. Like this:
11
11
12
12
``` rust
@@ -25,10 +25,10 @@ position having a type name rather than the value. Careful readers will also
25
25
note that tuples are heterogeneous: we have an ` i32 ` and a ` &str ` in this tuple.
26
26
You haven't seen ` &str ` as a type before, and we'll discuss the details of
27
27
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
29
29
we'll learn more soon.
30
30
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
32
32
an example:
33
33
34
34
``` rust
@@ -40,8 +40,8 @@ println!("x is {}", x);
40
40
Remember before when I said the left-hand side of a ` let ` statement was more
41
41
powerful than just assigning a binding? Here we are. We can put a pattern on
42
42
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.
45
45
46
46
This pattern is very powerful, and we'll see it repeated more later.
47
47
@@ -83,18 +83,18 @@ fn main() {
83
83
}
84
84
```
85
85
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.
89
89
90
90
Tuples are a very simple data structure, and so are not often what you want.
91
91
Let's move on to their bigger sibling, structs.
92
92
93
93
## Structs
94
94
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
96
96
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:
98
98
99
99
``` rust
100
100
struct Point {
@@ -143,8 +143,7 @@ This will print `The point is at (5, 0)`.
143
143
## Tuple Structs and Newtypes
144
144
145
145
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:
148
147
149
148
150
149
``` {rust}
@@ -182,7 +181,7 @@ Now, we have actual names, rather than positions. Good names are important,
182
181
and with a struct, we have actual names.
183
182
184
183
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
186
185
you create a new type that's a synonym for another one:
187
186
188
187
``` {rust}
@@ -199,7 +198,7 @@ destructuring `let`.
199
198
200
199
## Enums
201
200
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
203
202
feature of Rust, and are used throughout the standard library. This is an enum
204
203
that is provided by the Rust standard library:
205
204
0 commit comments