Rust doesn't allow const in trait objects.
Just like static functions, associated constants aren't stored on the method table. If the trait or any subtrait contain an associated constant, they cannot be made into an object.
this is stupid. i've used "trait object constants" or "virtual static variables" or "abstract ClassVar" in Python corrscope, and I'm using them (except as virtual methods because C++ doesn't allow virtual static properties) in C++...
and why doesn't Rust let you store constants in the trait vtable? What's the reasoning behind forcing you to call a getter instead of just letting you store constants there?
FamiTracker needs to store metadata in "pointer to base". It adds class fields initialized through the base constructor.
famitracker used the "store the metadata as fields in the base class" approach. It takes up (negligible) space in each instance, but is faster because there's less indirection on access. But it makes the base class constructor ugly, with parameters determined by "which subclass is calling my constructor", not "what values am I holding".
Corrscope (by me) needs to store class-level metadata in "objects". It accesses "class variables". I designed an abstract_classvar object, which makes Mypy understand what I'm doing perfectly.
My new C++ program (by me) also needs to store metadata accessible via "pointer to instance". I use virtual getters. But it doesn't need to be a virtual function. It doesn't even reference this at all. It only cares about "what type is this pointing to, and what metadata is stored in the type".
"virtual getter method" works in C++, Java, Rust, everywhere... but requires quite a bit of boilerplate in each subclass. I don't know if it's slow or not. it's so easy in Python and neglected everywhere else.
Qt has a single getter pointing to a giant pile of metadata. Each class (not object) has a single metadata object (generated by moc, or verdigris if you're cool). https://doc.qt.io/qt-5/qmetaobject.html
A single QMetaObject instance is created for each QObject subclass that is used in an application, and this instance stores all the meta-information for the QObject subclass.