[rust-dev] Opt-In Built-In Traits (was: Mutable files)

David Henningsson diwic at ubuntu.com
Wed Jul 23 12:52:56 PDT 2014

On 2014-07-21 19:17, Patrick Walton wrote:
> 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.
> * Causing a move when you thought you were copying results in a compiler
> error.
> * 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.

I find these arguments compelling, but if what we want to accomplish is 
a conscious choice between copy and move every time somebody makes a new 
struct, maybe "#[Deriving(Data)] struct Foo" vs "struct Foo" is not 
first-class enough.

Maybe the move vs copy should be done by using different keywords, a few 
brainstorming examples:

  * "datastruct" for copy, "struct" for move
  * "simplestruct" for copy, "complexstruct" for move
  * "struct" for copy, "class" or "object" for move


// David

More information about the Rust-dev mailing list