You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
storing an interface in a generic type, like ArrayList? #3
so I'm wondering how can I store instances of struct? Note, it's not limited to one implementation, I could have a MenuState, A Gameplay state, etc, so having it store anything that implements the State interface is necessary
I am planning to re-implement this module such that it would enable use cases like yours. It's currently more of an experiment in designing interface validation, but as you encountered it does not work with generic collections.
In order to do this, I will need to instead generate vtable style interfaces like std.mem.Allocator from the Interface(.{ ... }) definition.
Sorry it doesn't meet your current needs, but I think handling your use case in the near future is absolutely possible and what I want this module to do.
Sorry it doesn't meet your current needs, but I think handling your use case in the near future is absolutely possible and what I want this module to do.
I'm really curious to see how an automatic generation of vtables and their impls could be accomplished at comptime. From my limited digging into the issue, I concluded this isn't really possible without outside code generation due to the fact that reified types cannot have decls and never will.
@emperor-limitless@Xion, I have a PR up that adds vtable implemented interfaces. It's pretty close to what I was hoping to reach. Let me know if you have a chance to take a look: #9
Activity
nilslice commentedon Nov 26, 2024
Hey @emperor-limitless -
I am planning to re-implement this module such that it would enable use cases like yours. It's currently more of an experiment in designing interface validation, but as you encountered it does not work with generic collections.
In order to do this, I will need to instead generate vtable style interfaces like
std.mem.Allocatorfrom theInterface(.{ ... })definition.Sorry it doesn't meet your current needs, but I think handling your use case in the near future is absolutely possible and what I want this module to do.
Xion commentedon Jan 22, 2025
I'm really curious to see how an automatic generation of vtables and their impls could be accomplished at comptime. From my limited digging into the issue, I concluded this isn't really possible without outside code generation due to the fact that reified types cannot have decls and never will.
nilslice commentedon Oct 19, 2025
@emperor-limitless @Xion, I have a PR up that adds vtable implemented interfaces. It's pretty close to what I was hoping to reach. Let me know if you have a chance to take a look: #9
nilslice commentedon Oct 19, 2025
additionally, @emperor-limitless, I have a test that demonstrates the collection limitation you brought up: https://github.com/nilslice/zig-interface/blob/updated-interface/test/collections.zig, which should now be resolved.
nilslice commentedon Oct 28, 2025
I've merged #9 which now will let you specify the type of your container as the Interface type you define