lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Sat, Sep 9, 2017 at 6:41 PM, Soni L. <> wrote:
> Rust has compile-time traits. But it does not, in fact, have runtime traits.
> If you make a trait and impl that trait on someone else's struct, reflection
> with that struct will not be able to see your trait, and thus won't be able
> to make trait objects with it.

Since we're nailing down concepts here, I submit that such traits are
indeed dynamic. I have someone else's Foo struct, and implement Trait
for Foo. Box<Trait> is a trait object and has a vtable, so I can call
any Trait methods on it.  But true, there's a key difference. If I
receive a trait object, I can't magically upcast that into the 'real'
underlying type Foo, since that information is thrown away (this gets
called 'type erasure'). Is this perhaps what you meant?