On 11/8/11 9:12 AM, David Rajchenbach-Teller wrote:
Does this mean that we can only have one constructor?
If we wish to have several constructors – and if we accept that they
must not have the same name – the class could yield a full module, in
which each constructor is a function.

Yeah, we may want multiple constructors. I left it out due to simplicity, but I don't have any opposition. If we do have them, they should be named though, as you say.

What is the rationale behind **@class**?

Because you may want to e.g. register the instance with an observer, and if all you have is an alias to self you can't do that.

So a destructor cannot trigger cleanup of any heap-allocated data?

Right, but keep in mind that if a class instance contains the last reference to heap-allocated data, the destructor on that heap-allocated data will be called as usual.

Class instances are copyable if and only if the class has no
destructor and all of its fields are copyable. Class instances are
sendable if and only if all of its fields are sendable and the
class was not declared with **@class**.

No destructor? I would rather have guessed no constructor, what am I
missing?

Destructors are for classes that encapsulate things like OS file descriptors. If you copy their contents, you'd end up closing the file twice.

Classes may be type-parametric. Methods may not be
type-parametric.

Hmmm... What is the rationale?

Mostly because it's what we did before. I wouldn't be opposed to making methods type-parametric either, honestly.

I like it. Be warned that someone is bound to ask for RTTI to
pattern-match on interfaces and/or on interface fields.

Rust has always been slated to have reflection -- RTTI is baked into the system already, it's just a matter of implementing it.

One more question, though: what about class-less objects? I feel that
they could be quite useful to provide defer-style cleanup.

I'm not opposed to that, if we can make it work. Keep in mind that you can define nominal classes (and nominal items generally) inside functions already, so this is mostly a question of avoiding giving a class a name (and maybe closing over surrounding lexical items; the same memory management issues we have with closures apply, of course).

Patrick
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to