[rust-dev] Mutable files
pcwalton at mozilla.com
Mon Jul 21 10:17:05 PDT 2014
On 7/21/14 8:49 AM, Tobias Müller wrote:
> Patrick Walton <pcwalton at mozilla.com> wrote:
>> On 7/20/14 8:12 PM, David Henningsson wrote:
>>> From a language design perspective, maybe it would be more intuitive to
>>> have different syntaxes for copy and move, like:
> As a rust newbie, that aspect aways makes me a bit nervous. Two quite
> different operations with the same syntax and and simply changing a detail
> in the struct can be enough to switch between the two.
This is the reason for Opt-In Built-In Traits.
> AFAIK this also was one of the reasons (if not _the_ reason) why
> std::auto_ptr was deprecated in C++.
No, `auto_ptr` was deprecated because it copies, not moves, making it
hard to sensibly use in containers (among other things).
Comparisons between C++ aren't really relevant anyway because the
compiler catches any use-after-move at *compile time*, rather than at
runtime. This means that mistaking the two doesn't cause any harm:
* Causing a move when you thought you were copying results in a compiler
* Causing a copy when you thought you were moving is harmless, as any
implicit copy in Rust has *exactly the same runtime semantics* as a
move, except that the compiler prevents you from using the value again.
Again, we had that world before. It was extremely annoying to write
"move" all over the place. Be careful what you wish for.
More information about the Rust-dev