Can we simulate rust like traits in Zig (to add methods to a struct)?

There was concrete opaque types a while ago, which covers a lot of ground here. It’s possible right now, it’s not even difficult, but Zig is almost certainly not going to make it any easier than it is.

I think the aversion to not having private or read-only fields is 90% or more just discomfort at the thought that it allows Bad Things to occur, and just a sliver of actual problems which actually arise from meddling with a struct’s fields. I can’t say I’ve ever had to fix a bug arising from code I wrote which messes with the internal logic of a stdlib container, it’s possible to do it, but not likely to occur by accident.

3 Likes