Skip to content

Commit 44338cb

Browse files
committed
rollup merge of #24672: steveklabnik/edit_tuple_structs
I thought I edited all the last little chapters, but I missed this one. r? @alexcrichton
2 parents cfbc5be + b0105b5 commit 44338cb

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/doc/trpl/tuple-structs.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
% Tuple Structs
22

3-
Rust has another data type that's like a hybrid between a tuple and a struct,
4-
called a *tuple struct*. Tuple structs do have a name, but their fields don't:
3+
Rust has another data type that's like a hybrid between a [tuple][tuple] and a
4+
[struct][struct], called a ‘tuple struct’. Tuple structs have a name, but
5+
their fields don’t:
56

6-
```{rust}
7+
```rust
78
struct Color(i32, i32, i32);
89
struct Point(i32, i32, i32);
910
```
1011

12+
[tuple]: primitive-types.html#tuples
13+
[struct]: structs.html
14+
1115
These two will not be equal, even if they have the same values:
1216

13-
```{rust}
17+
```rust
1418
# struct Color(i32, i32, i32);
1519
# struct Point(i32, i32, i32);
1620
let black = Color(0, 0, 0);
@@ -20,7 +24,7 @@ let origin = Point(0, 0, 0);
2024
It is almost always better to use a struct than a tuple struct. We would write
2125
`Color` and `Point` like this instead:
2226

23-
```{rust}
27+
```rust
2428
struct Color {
2529
red: i32,
2630
blue: i32,
@@ -37,12 +41,12 @@ struct Point {
3741
Now, we have actual names, rather than positions. Good names are important,
3842
and with a struct, we have actual names.
3943

40-
There _is_ one case when a tuple struct is very useful, though, and that's a
41-
tuple struct with only one element. We call this the *newtype* pattern, because
44+
There _is_ one case when a tuple struct is very useful, though, and thats a
45+
tuple struct with only one element. We call this the newtype pattern, because
4246
it allows you to create a new type, distinct from that of its contained value
4347
and expressing its own semantic meaning:
4448

45-
```{rust}
49+
```rust
4650
struct Inches(i32);
4751

4852
let length = Inches(10);
@@ -52,5 +56,5 @@ println!("length is {} inches", integer_length);
5256
```
5357

5458
As you can see here, you can extract the inner integer type through a
55-
destructuring `let`, as we discussed previously in 'tuples.' In this case, the
59+
destructuring `let`, as we discussed previously in tuples’. In this case, the
5660
`let Inches(integer_length)` assigns `10` to `integer_length`.

0 commit comments

Comments
 (0)