[rust-dev] Representing foreign class inheritance in Rust
mikhail.zabaluev at gmail.com
Thu Oct 2 22:23:44 PDT 2014
I've realized that as long as I only get the instance structures by pointer
and treat them as non-copyable (which one should in case of GObject),
traits-as-object-interface are unnecessary and I only need the traits for
instance upcasting. When the trait reform lands, the amount of boilerplate
per class is expected to become nearly constant, which is OK for me as I'm
going to apply a code generator.
I've updated the gist with a cleaner solution:
2014-10-03 1:40 GMT+03:00 Mikhail Zabaluev <mikhail.zabaluev at gmail.com>:
> While working on bindings to the GObject type system, I could not help
> noticing the amount of boilerplate I ended up with trying to represent
> OOP-style class inheritance:
> The trait reform and UFCS should take away much of the pain, but a really
> nice solution would be a way to annotate `impl A for InstA` as
> auto-derivable or "inheritable", so that any type implementing
> `Inherit<InstA>` (here, a proposed special standard trait) would
> automatically get its own implementation of `A` in terms of the upcast
> provided by `Inherit`. Furthermore, that implicit trait implementation
> would in turn be "inheritable", so that any indirect subclass would
> implement `A`, and any other inheritable traits in the chain of its
> parents, for free.
> Not all traits would be available for such treatment; dependencies on
> static properties of Self a la `fn new() -> Self` would preclude it. But
> the traits that a classic OOP hierarchy lends itself to, should be just
> what the doctor ordered.
> Note also how the default implementations of the inheritable trait methods
> are amenable to tail call elimination. If the compiler itself would
> generate those shims, it could just emit inherited impls' vtable entries as
> trampolines to the base impl, and similarly apply the tail-call hinting
> during static monomorphization.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Rust-dev