@@ -138,17 +138,19 @@ corresponding fields in `user1`, but we can choose to specify values for as
138
138
many fields as we want in any order, regardless of the order of the fields in
139
139
the struct’s definition.
140
140
141
- Note that the struct update syntax uses ` = ` like an assignment; this is because
142
- it moves the data, just as we saw in the [ “Variables and Data Interacting with
143
- Move”] [ move ] <!-- ignore --> section. In this example, we can no longer use
144
- ` user1 ` as a whole after creating ` user2 ` because the ` String ` in the
145
- ` username ` field of ` user1 ` was moved into ` user2 ` . If we had given ` user2 ` new
146
- ` String ` values for both ` email ` and ` username ` , and thus only used the
147
- ` active ` and ` sign_in_count ` values from ` user1 ` , then ` user1 ` would still be
148
- valid after creating ` user2 ` . Both ` active ` and ` sign_in_count ` are types that
149
- implement the ` Copy ` trait, so the behavior we discussed in the [ “Stack-Only
150
- Data: Copy”] [ copy ] <!-- ignore --> section would apply. We can still use
151
- ` user1.email ` in this example, since its value was _ not_ moved out.
141
+ Note that the struct update syntax uses ` = ` like an assignment, so it handles
142
+ copies and moves just as we saw in the [ “Variables and Data Interacting with
143
+ Move”] [ move ] <!-- ignore --> section. Fields that are of a type that implement
144
+ the ` Copy ` trait are copied from ` user1 ` to ` user2 ` , as discussed in [ “Stack-Only
145
+ Data: Copy”] [ copy ] <!-- ignore --> . Fields that are of a type that do not
146
+ implement the ` Copy ` trait are moved. In this example ` user1.active ` and
147
+ ` user1.sign_in_count ` have been copied, and so access to them is still valid.
148
+ ` user1.email ` has not been moved and so access to it is also still valid.
149
+ However ` user1.username ` has been moved and so access to it is no longer valid.
150
+ Furthermore, because one of its fields has been moved, access to ` user1 ` directly
151
+ is also no longer valid (despite access to ` user1.active ` , ` user1.sign_in_count `
152
+ and ` user1.email ` still being valid).
153
+
152
154
153
155
### Using Tuple Structs Without Named Fields to Create Different Types
154
156
0 commit comments