Hello everyone. I am looking to follow up on the “Fields in Traits” RFC which aims to provide the ability for a trait to contain fields as well as methods. As currently envisioned his would boil down to an memory offset which could be used statically or put into the vtable to locate the desired field in implementing types.
Continuing the discussion from https://github.com/rust-lang/rfcs/pull/1546
Current RFC state: https://github.com/nikomatsakis/fields-in-traits-rfc/blob/master/0000-fields-in-traits.md
The main thing I am looking to do right now is collect different possible use cases and requirements for this feature. I have collected a couple bellow gathered from the RFC, discussions and personal use cases. Please let me know of others.
- Performance. This can transform a virtual method call into an indirect lookup.
- Better borrow granularity. This can allow concurrent borrows of different part of an object from a trait as each virtual field can be borrowed independently.
- Convenience: This allows
foo.x =as opposed to a collection of getters/setters.
- Integration with other object systems. (ex: GObject) I think this falls under “Convenience”
If you want me to detail any of these use cases just ask.
It’s worth noting that I believe 1 and 4 are mutually exclusive (unless we are going to generate vtables at runtime) but the others seem to be covered by the RFC as is with only minor rewording.