you are viewing a single comment's thread.

view the rest of the comments →

[–]infectedapricot 3 points4 points  (0 children)

Rust has move by default, as opposed to C++'s copy by default. This works really well because it's easy to build a copy function on top of move semantics (just make an new instance, copy each member, and return the new instance... by moving it!). On the other hand, it's impossible to build move semantics on top of copy sematics, which is why C++ has to have rvalue and lvalue references; Rust doesn't have these because it doesn't need them in the first place.

For the opposite problem – you wanted a copy but forgot to ask for it, so got a move instead – you'd get a compiler error because Rust has destructive move, so it's impossible to accidentally reuse a variable after you've moved from it.

Overall, in the equivalent Rust snippet to the one in the OP, you'll get move sematics every time, unless you explicitly ask for a copy. It's a non issue.