zig.guide
zig.guide copied to clipboard
Chapter 1: Explicitly explain switching on enums and tagged structs
When I encountered the tagged enums, I was confused about the .a syntax in the switch, which I hadn't encountered before - I could guess what was going on, but it wasn't clear why it worked.
After playing around I'm assuming it is a special case of switching on an enum, which also wasn't explained anywhere in the docs.
So, I explain how switching on enums works in the enums section, and then explain how captures layer onto that in the tagged structs section, explicitly pointing out its similarity to switching on the enum, instead of presenting it all at once without explaining what the enum branch syntax is about.
I considered doing two enum switches, one with the full Volume.level syntax in the switch branches, and one with the shorthand, but left that explained in the text. I do think it would make it even clearer, but am not sure it's worth the added verbosity.
Also, I'm making assumptions about how things work here, I don't actually know how Zig works, so let me know if I've misunderstood!
After running into the shorthand syntax again in #115 I came back and explained it earlier here. These changes will conflict with #115, but I think this is a better way to introduce it I think, so I think we should merge this PR and then I can update #115 to make sense with the new changes.