Skip to content

Commit

Permalink
Clarify that user1 can't be used as a whole instance. Fixes rust-lang…
Browse files Browse the repository at this point in the history
  • Loading branch information
carols10cents committed Oct 27, 2022
1 parent d339373 commit a371f82
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/ch05-01-defining-structs.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ the struct’s definition.
Note that the struct update syntax uses `=` like an assignment; this is because
it moves the data, just as we saw in the [“Variables and Data Interacting with
Move”][move]<!-- ignore --> section. In this example, we can no longer use
`user1` after creating `user2` because the `String` in the `username` field of
`user1` was moved into `user2`. If we had given `user2` new `String` values for
both `email` and `username`, and thus only used the `active` and
`sign_in_count` values from `user1`, then `user1` would still be valid after
creating `user2`. Both `active` and `sign_in_count` are types that implement
the `Copy` trait, so the behavior we discussed in the [“Stack-Only Data:
Copy”][copy]<!-- ignore --> section would apply.
`user1` as a whole after creating `user2` because the `String` in the
`username` field of `user1` was moved into `user2`. If we had given `user2` new
`String` values for both `email` and `username`, and thus only used the
`active` and `sign_in_count` values from `user1`, then `user1` would still be
valid after creating `user2`. Both `active` and `sign_in_count` are types that
implement the `Copy` trait, so the behavior we discussed in the [“Stack-Only
Data: Copy”][copy]<!-- ignore --> section would apply.

### Using Tuple Structs Without Named Fields to Create Different Types

Expand Down

0 comments on commit a371f82

Please sign in to comment.