Discussion on: Interfaces in Zig

jackji profile image
jack • Edited on

Nice explanation!
Though the problem of the style is parent object must be valid as long as it’s interface is being used, which is easy to break if you “accidentally” allocated object on stack in some factory and returns pointer to it’s inner-interface, so heap allocation must be used to avoid that.
There’s a nice general purpose interface lib worth checking out: github.com/alexnask/interface.zig

EDIT: Turns out the zig-dev team have noticed the issue, a proposal has been accepted:

david_vanderson profile image
David Vanderson Author

Yes you are right about having to be careful. Thanks for the link!