|
|
|
|
|
by coderenegade
1262 days ago
|
|
I found the copy/move situation in Rust to be far less intuitive than in C++. In C++, move semantics are obvious because they rely on std::move and the && operator, whereas in Rust, similar behavior seemed to depend on the object type. Even more confusingly, Rust has its own move operator as well, despite destructive move being the default behavior for assignment. I found it frustrating enough that I put the language down and just went back to using C++. |
|
In Rust it's also obvious because every = is a move. Confusion comes from tutorials pretending for too long that it's not.
> whereas in Rust, similar behavior seemed to depend on the object type.
It's best to think of that as an exception to the rule created specifically for numbers and other similar small, cheaply copied things.
If you need to move `a` but `a` has a trait Copy then you copy instead.
> Rust has its own move operator as well, despite destructive move being the default behavior for assignment.
I don't think that's true? Rust has a `move` keyword but it's a part of closure definition that makes it take all the variables from its environment by move, even if it doesn't need it. Unless you are talking about something else...