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
In Destructuring pt2, in the second code snippet, regarding the first option of the match statement, it says
"...in the first approach we dereference x to a temporary variable with type Enum1 (which copies the value in x)...".
Enum1 has copy semantics, so it makes sense that *x (the value in x) is copied into a temp variable. From that I conclude that if there is a match statement on a dereference of an object with copy semantics, a temporary variable is created and the value of *x is copied into it. So far so good.
However, in the third code snippet, option 1 of the match statement, where the value of x (now of type Enum2) has move semantics, shouldn't the same hold true, but this time, with a move operation, making this scenario illegal? That is, when creating a match statement on a dereference of an object with move semantics, it should, following the same logic, result in a temporary variable into which *x would be moved? Or does that not apply in case of object with move semantics? That is, if you have a match statements on a dereference of an object with move semantics, no temporary variable is created?
I don't know the answer as I'm just starting out with Rust and it gets me confused. I think this point should be clarified.
The text was updated successfully, but these errors were encountered:
In Destructuring pt2, in the second code snippet, regarding the first option of the match statement, it says
Enum1
has copy semantics, so it makes sense that*x
(the value inx
) is copied into a temp variable. From that I conclude that if there is a match statement on a dereference of an object with copy semantics, a temporary variable is created and the value of*x
is copied into it. So far so good.However, in the third code snippet, option 1 of the match statement, where the value of
x
(now of typeEnum2
) has move semantics, shouldn't the same hold true, but this time, with a move operation, making this scenario illegal? That is, when creating a match statement on a dereference of an object with move semantics, it should, following the same logic, result in a temporary variable into which*x
would be moved? Or does that not apply in case of object with move semantics? That is, if you have a match statements on a dereference of an object with move semantics, no temporary variable is created?I don't know the answer as I'm just starting out with Rust and it gets me confused. I think this point should be clarified.
The text was updated successfully, but these errors were encountered: