You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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"
The text was updated successfully, but these errors were encountered: