zig.guide icon indicating copy to clipboard operation
zig.guide copied to clipboard

How to implement "interface" or "trait" like semantics in Zig

Open cinemast opened this issue 5 years ago • 2 comments
trafficstars

Hi!

Thanks for your great effort on documenting zig.

It would be great to have a section explaining how to implement golang like interfaces or rust like traits in zig. Including examples with / without state (self) and with / without dynamic dispatching.

cinemast avatar Jul 16 '20 18:07 cinemast

I just saw this page: https://www.nmichaels.org/zig/interfaces.html

Maybe this can be used for the website.

KaneRoot avatar Aug 05 '20 22:08 KaneRoot

related issue without conclusive statement yet https://github.com/ziglang/zig/issues/1268

matu3ba avatar Apr 11 '22 16:04 matu3ba

There are still no current plans to introduce a traits-like feature in zig & there hasn't emerged a standard way of doing interfaces like this; closing this for the foreseeable future

Sobeston avatar Sep 12 '23 16:09 Sobeston