]> git.proxmox.com Git - rustc.git/blobdiff - src/doc/book/second-edition/src/ch05-01-defining-structs.md
New upstream version 1.23.0+dfsg1
[rustc.git] / src / doc / book / second-edition / src / ch05-01-defining-structs.md
index d2c3f9dfafb0eb93cdc4c841e179ca962af28e4d..3bc5b20ae19e6e20522f50951a9982113d6346ff 100644 (file)
@@ -112,7 +112,7 @@ and username and returns a `User` instance</span>
 It makes sense to name the function arguments with the same name as the struct
 fields, but having to repeat the `email` and `username` field names and
 variables is a bit tedious. If the struct had more fields, repeating each name
-would get even more annoying. Luckily, there's a convenient shorthand!
+would get even more annoying. Luckily, theres a convenient shorthand!
 
 ### Using the Field Init Shorthand when Variables and Fields Have the Same Name
 
@@ -184,7 +184,7 @@ let user2 = User {
 <span class="caption">Listing 5-6: Creating a new `User` instance using some of
 the values from `user1`</span>
 
-Using struct update syntax, we can achieve the same effect with less code,
+Using struct update syntax, we can achieve the same effect with less code, as
 shown in Listing 5-7. The syntax `..` specifies that the remaining fields not
 explicitly set should have the same value as the fields in the given instance.
 
@@ -210,7 +210,7 @@ let user2 = User {
 };
 ```
 
-<span class="caption">Listing 5-7: Using struct update syntax to set new
+<span class="caption">Listing 5-7: Using struct update syntax to set new
 `email` and `username` values for a `User` instance but use the rest of the
 values from the fields of the instance in the `user1` variable</span>
 
@@ -220,12 +220,13 @@ different value for `email` and `username` but has the same values for the
 
 ### Tuple Structs without Named Fields to Create Different Types
 
-We can also define structs that look similar to tuples, called *tuple structs*,
-that have the added meaning the struct name provides, but don’t have names
-associated with their fields, just the types of the fields. Tuple structs are
-useful when you want to give the whole tuple a name and make the tuple be a
-different type than other tuples, but naming each field as in a regular struct
-would be verbose or redundant.
+We can also define structs that look similar to tuples (which were discussed in
+Chapter 3), called *tuple structs*, that have the added meaning the struct name
+provides, but don’t have names associated with their fields; rather, they just
+have the types of the fields. Tuple structs are useful when you want to give
+the whole tuple a name and make the tuple be a different type than other
+tuples, but naming each field as in a regular struct would be verbose or
+redundant.
 
 To define a tuple struct you start with the `struct` keyword and the struct
 name followed by the types in the tuple. For example, here are definitions and
@@ -244,9 +245,9 @@ instances of different tuple structs. Each struct we define is its own type,
 even though the fields within the struct have the same types. For example, a
 function that takes a parameter of type `Color` cannot take a `Point` as an
 argument, even though both types are made up of three `i32` values. Otherwise,
-tuple struct instances behave like tuples, which we covered in Chapter 3: you
-can destructure them into their individual pieces, you can use a `.` followed
-by the index to access an individual value, and so on.
+tuple struct instances behave like tuples: you can destructure them into their
+individual pieces and you can use a `.` followed by the index to access an
+individual value, and so on.
 
 ### Unit-Like Structs without Any Fields
 
@@ -254,7 +255,7 @@ We can also define structs that don’t have any fields! These are called
 *unit-like structs* since they behave similarly to `()`, the unit type.
 Unit-like structs can be useful in situations such as when you need to
 implement a trait on some type, but you don’t have any data that you want to
-store in the type itself. We’ll be discussing traits in Chapter 10.
+store in the type itself. We’ll discuss traits in Chapter 10.
 
 > ### Ownership of Struct Data
 >
@@ -264,10 +265,10 @@ store in the type itself. We’ll be discussing traits in Chapter 10.
 > data to be valid for as long as the entire struct is valid.
 >
 > It’s possible for structs to store references to data owned by something else,
-> but to do so requires the use of *lifetimes*, a Rust feature that is discussed
-> in Chapter 10. Lifetimes ensure that the data referenced by a struct is valid
-> for as long as the struct is. Let’s say you try to store a reference in a
-> struct without specifying lifetimes, like this:
+> but to do so requires the use of *lifetimes*, a Rust feature that we’ll
+> discuss in Chapter 10. Lifetimes ensure that the data referenced by a struct
+> is valid for as long as the struct is. Let’s say you try to store a reference
+> in a struct without specifying lifetimes, like this:
 >
 > <span class="filename">Filename: src/main.rs</span>
 >
@@ -305,6 +306,6 @@ store in the type itself. We’ll be discussing traits in Chapter 10.
 >   |            ^ expected lifetime parameter
 > ```
 >
-> We’ll discuss how to fix these errors so you can store references in structs
-> in Chapter 10, but for now, we’ll fix errors like these using owned types like
-> `String` instead of references like `&str`.
+> In Chapter 10, we’ll discuss how to fix these errors so you can store
+> references in structs, but for now, we’ll fix errors like these using owned
+> types like `String` instead of references like `&str`.