Ok, new to Zig, maybee too soon for me to be skimming the standard library code, but there isn’t much documentation. (Not a complaint - I know it is a new language, and frankly, the code almost looks understandable to me at this point, which is sort of amazing to me).
So, fn GenericWriter defines a structure in it’s body, and returns it (which is cool). There are a few functions defined in the structure, such as writeStructEndian that have bodies like: return @errorCast(self.any().writeStructEndian(value, endian));.
So, the any function in the struct, also returns an anonymous struct having fields: .context and .writeFn … so here’s my confusion: in following self.any(), I’m assuming that writeStructureEndian is then called on the anonymous structure? How does that work? The anonymous structure doesn’t define that function and Zig doesn’t have inheritance?
The anyonymous struct literal creates an instance with the type of the return type of the any function and the return type has the writeStructureEndian method.