Re:Deriving Traits in Rust with Procedural Macros
by a1369209993 on Thursday January 03, 2019 @09:12PM
(#18821420)
> I am not sure what you are trying to say. [Couple paragraphs rephrasing what I said]
Yep, that's what I was trying to say. (Although I'd hadn't remembered that the Copy trait actually enforced bitwise-exact-copies-only, because why would you want (implicit) non-exact copies.)
I am not sure what you are trying to say. This:
is not possible in Rust if a's type is not a copy type. a will be moved when calling bar, so trying to pass it to baz will result in a compiler error.The story is quite simple: a value is always moved in a function call, unless it is a copy type (the type implements the Copy trait). When the type is a copy type, a bit-wise copy is made. References are not special: immutable references are copy types. Mutable references are not copy types (otherwise, they could be aliased).
You can find an overview of all copy types in the standard library in the implementations section of the Copy trait:
https://doc.rust-lang.org/beta/std/marker/trait.Copy.html#fo...