Printing Zig Structs
7 points by rcalixte
7 points by rcalixte
Cool! This is nice to know.
One thing that's pretty cool and non-obvious is that this is a great example of comptime. That "error: unused argument" compile error they mention? That's entirely enforced in normal code with no specific compiler support!
If you go to the docs for the print function and scroll to the bottom to see the code, you can see exactly how it checks the args at compile time and can raise a compile error from within a simple if statement! That's incredibly powerful if you're a library author, and it doesn't require encoding strange constraints into a type system that wasn't built for that kind of reasoning.
Which brings us to what I've really been enjoying about Zig lately ...it's all just sitting there with no magic. If you don't like that it's yelling at you for those unused arguments, you should be able to just copy the function and modify it so that it doesn't do that.