Skip to content

Commit 1661947

Browse files
committed
Auto merge of #28182 - jackwilsonv:patch-2, r=steveklabnik
r? @steveklabnik ##### About the `struct` section specifically: I wasn't sure how you'd feel about the first instance since it was originally capitalized, happy to change it back if you think that's better. Also, I left 'tuple struct' as is since together it isn't a keyword. The first instance currently has single quotes but the others have nothing. I think that feels right. ##### Generally: I'm working through the book now and I'm happy to keep updating this branch with any formatting tweaks or updates I find if that's easier for you guys, otherwise I'll just create smaller PRs as I go. Just let me know.
2 parents 69c3b39 + 28bf68f commit 1661947

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/doc/trpl/structs.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
% Structs
22

3-
Structs are a way of creating more complex data types. For example, if we were
3+
`struct`s are a way of creating more complex data types. For example, if we were
44
doing calculations involving coordinates in 2D space, we would need both an `x`
55
and a `y` value:
66

@@ -9,7 +9,7 @@ let origin_x = 0;
99
let origin_y = 0;
1010
```
1111

12-
A struct lets us combine these two into a single, unified datatype:
12+
A `struct` lets us combine these two into a single, unified datatype:
1313

1414
```rust
1515
struct Point {
@@ -28,14 +28,14 @@ There’s a lot going on here, so let’s break it down. We declare a `struct` w
2828
the `struct` keyword, and then with a name. By convention, `struct`s begin with
2929
a capital letter and are camel cased: `PointInSpace`, not `Point_In_Space`.
3030

31-
We can create an instance of our struct via `let`, as usual, but we use a `key:
31+
We can create an instance of our `struct` via `let`, as usual, but we use a `key:
3232
value` style syntax to set each field. The order doesn’t need to be the same as
3333
in the original declaration.
3434

3535
Finally, because fields have names, we can access the field through dot
3636
notation: `origin.x`.
3737

38-
The values in structs are immutable by default, like other bindings in Rust.
38+
The values in `struct`s are immutable by default, like other bindings in Rust.
3939
Use `mut` to make them mutable:
4040

4141
```rust
@@ -91,7 +91,7 @@ fn main() {
9191
# Update syntax
9292

9393
A `struct` can include `..` to indicate that you want to use a copy of some
94-
other struct for some of the values. For example:
94+
other `struct` for some of the values. For example:
9595

9696
```rust
9797
struct Point3d {
@@ -121,7 +121,7 @@ let point = Point3d { z: 1, x: 2, .. origin };
121121
# Tuple structs
122122

123123
Rust has another data type that’s like a hybrid between a [tuple][tuple] and a
124-
struct, called a ‘tuple struct’. Tuple structs have a name, but
124+
`struct`, called a ‘tuple struct’. Tuple structs have a name, but
125125
their fields don’t:
126126

127127
```rust
@@ -140,7 +140,7 @@ let black = Color(0, 0, 0);
140140
let origin = Point(0, 0, 0);
141141
```
142142

143-
It is almost always better to use a struct than a tuple struct. We would write
143+
It is almost always better to use a `struct` than a tuple struct. We would write
144144
`Color` and `Point` like this instead:
145145

146146
```rust
@@ -158,7 +158,7 @@ struct Point {
158158
```
159159

160160
Now, we have actual names, rather than positions. Good names are important,
161-
and with a struct, we have actual names.
161+
and with a `struct`, we have actual names.
162162

163163
There _is_ one case when a tuple struct is very useful, though, and that’s a
164164
tuple struct with only one element. We call this the ‘newtype’ pattern, because
@@ -180,13 +180,13 @@ destructuring `let`, just as with regular tuples. In this case, the
180180

181181
# Unit-like structs
182182

183-
You can define a struct with no members at all:
183+
You can define a `struct` with no members at all:
184184

185185
```rust
186186
struct Electron;
187187
```
188188

189-
Such a struct is called ‘unit-like’ because it resembles the empty
189+
Such a `struct` is called ‘unit-like’ because it resembles the empty
190190
tuple, `()`, sometimes called ‘unit’. Like a tuple struct, it defines a
191191
new type.
192192

@@ -195,6 +195,6 @@ marker type), but in combination with other features, it can become
195195
useful. For instance, a library may ask you to create a structure that
196196
implements a certain [trait][trait] to handle events. If you don’t have
197197
any data you need to store in the structure, you can just create a
198-
unit-like struct.
198+
unit-like `struct`.
199199

200200
[trait]: traits.html

0 commit comments

Comments
 (0)