Learning Zig by creating a parser

It depends. I’d say that if you’re dealing with a data structure that holds pointers (or slices,) it’s probably better to pass in a pointer to the struct versus creating it in the function. Creating it in the function and returning it can open the door to having Pointers to Temporary Memory . Also, as you mention, receiving a pointer to the list simplifies the lifetime issues because that would be the list owner’s responsibility.

Your code is basically doing the same job as the StaticStringMap. In this case I’d say it would simplify your code because all the data needed for the lookup is right there in the map and the actual lookup is just a one-liner.

1 Like