this post was submitted on 24 Mar 2024
26 points (96.4% liked)
Rust
6032 readers
2 users here now
Welcome to the Rust community! This is a place to discuss about the Rust programming language.
Wormhole
Credits
- The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Working on some form of inheritance in rust. It's my first foray into procedural macros and so far it's fun. The idea is quite simple: generate structs with common attributes (and eventually functions) instead writing them yourself.
becomes
not
The latter leads to indirection which I'm not a fan of.
Last week I squashed one bug on the order of attributes according to inheritance. In the example above
attr2
was coming beforeattr1
. A feature is nearly done to exclude theParent
from the output and only output the child. That's useful for parents that just serve as holders for shared attributes.The goal for v1 was to also support basic inheritance of implementations:
Parent
has animpl
block, then that block is copied for theChild
. Not sure yet if I'll implement overrides in v1 or v2. Overrides being ifParent
implementsdo_something()
andChild
does too, then the implementation ofParent
is not copied into theimpl
block.That's what I'll try to tackle in the coming weeks.