Rust RFC: Opt-in Builtin Traits
smallcultfollowing.com
smallcultfollowing.com
Please implement this RFC. I really hope this gets in before Rust 1.0. I'm extremely excited and looking forward to using Rust in all my hobby projects once it stabilizes, but honestly when going through the tutorial this stood out as the only ugly wart in an otherwise amazingly beautiful language.
I'd be interested to hear if people unfamiliar with Rust can make head or tail of it. :)
> In particular the move/copy/clone semantics would (under this proposal) no longer be chosen automatically
(Technically, it's just the move semantics: i.e. if passing a value around by-value (i.e. `a = b` like C, shallow-copying the bytes of the values) makes the compiler consider the source unreadable (a move, non-Pod types) or just duplicates the data, leaving the source still readable (an "implicit copy", Pod types).)
You're the one who's been consistently curating std::num for many many months!
But more specifically, this part of the post struck me:
> struct Cell<T> {
> priv value: T
> }
> This is a perfectly ordinary struct, and hence the
> compiler would conclude that cells are freezable
> (if T is freezable) and so forth.
So how does it work, in the opt-in case, if Cell should be freezable only if T is freezable? Can you declare this kind of expectation and how complex does it get (particularly when considering several different traits)? impl<T: Freeze> Freeze for Cell<T> { }
> I'd rather see these kinds of traits always be implicit, because that allows for more interaction potential between independent libraries.Quite the opposite: them being implicit causes trouble with interaction between independent libraries. Because at present, a seemingly innocuous change deep in the internals of one library can prevent its being used in another library—for example, a POD type can have an owned type added to it, and all of a sudden utterly independent code that depended upon its POD behaviour will fail due to move semantics on the linear types.
If it's just about making sure library writers don't accidentally fail a changed contract just make it so that they can declare an explicit contract that will cause an error if they don't meet and thus make clear the contracts they intend to continue honoring.
This makes the error explicit for exactly the right person in the event of a contract change: the library writer if they break without intending to and the user of the library if they are using the library in a way that they expect to work but were not guaranteed to by the library writer.
> impl<T: Freeze> Freeze for Cell<T> { }
I see. Is it multiple statements for multiple traits or can theybe combined into one statement? Forgive the newbish question.
On the Cell Freeze matter: I don't understand your question. Can you clarify what you mean?