On Fri, Jan 17, 2014 at 8:07 PM, Daniel Micay <[email protected]> wrote: > On Fri, Jan 17, 2014 at 7:53 PM, Josh Haberman <[email protected]> wrote: >> >> Are you saying (if I may lapse into C++ vocab for a moment) that I can't >> hide the copy constructor? Anyone can copy my non-mut struct into a >> mut struct at any time and I don't have any say in the matter? >> >> Feel free to correct this into Rust-speak. :) > > Every type in Rust can be assigned, passed or returned by-value. This > is always semantically equivalent to a shallow copy, as they are in C. > If the type has a destructor, closure or `&mut T` inside then the copy > is considered a move of ownership. > > That's why there's a `Clone` trait in the standard library. It's the > minimum work to go from a non-owning reference to a value, rather than > just being the built-in shallow copy potentially moving ownership from > the source to the destination. > > You're also free to make fields private.
For example, you can have a type with private fields and the `#[no_send]` attribute. You can then take it by-value in a function returning the thread-safe type without `#[no_send]`. If it has a destructor, then the caller is unable to implicitly copy it without moving ownership and you would need to implement `Clone` to permit making more instances. _______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
