Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explain struct partial initiation/update syntax in more detail #315

Closed
jeekobu opened this issue Apr 10, 2018 · 0 comments
Closed

Explain struct partial initiation/update syntax in more detail #315

jeekobu opened this issue Apr 10, 2018 · 0 comments
Assignees
Labels
New Content Missing features or aspects of language not currently documented.

Comments

@jeekobu
Copy link

jeekobu commented Apr 10, 2018

When reading about struct update syntax in The Book 2nd Edition, I wondered what would happen with Copy field members versus Clone field members versus neither. Googling around didn't help (if there's an RFC I couldn't find it) and eventually I just used the playground to figure out the behavior: Copy fields are copied, other fields are moved, possibly leading to a "partially moved" struct.

It would be nice if the book and/or reference spelled this out.

Citations:
https://doc.rust-lang.org/reference/expressions/struct-expr.html
"with [...] the values in the base expression for all other fields", 'with' is vague

https://doc.rust-lang.org/stable/book/second-edition/ch05-01-defining-structs.html
"use the rest of the values from the fields of the instance", 'use' is vague

https://doc.rust-lang.org/nightly/book/first-edition/structs.html#update-syntax
"it will copy the values", technically not true for non-Copy types

https://play.rust-lang.org/?gist=cb23fb3f9f9c631370b2b631367b8b16&version=stable
Example of a "partially moved value"

@matthewjasper matthewjasper self-assigned this Apr 10, 2018
@Havvy Havvy added the New Content Missing features or aspects of language not currently documented. label Aug 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New Content Missing features or aspects of language not currently documented.
Projects
None yet
Development

No branches or pull requests

3 participants