Closed efjimm closed 3 months ago
Try to run the simple_router
example and you'll see that it works. Why do you open an issue when you haven't even tried?
Your assumptions are wrong. When you look at the code, you will see that the opaque type is created per invocation and its init function is called.
My apologies - this issue only exists on the 0.12 branch. I didn't believe the compilers handling of this had changed between versions so I didn't try 0.11. Given that the 0.12 release of Zig imminent this will still need to be addressed eventually.
Ah, I see, thanks for pointing that out. Looking at the code, I think it's a good thing it has to be changed, exactly because of the ambiguity about the memory of the opaqe type's vars. I also found other things in the Router that are worth rewriting.
RequestHandler
creates a closure over the passed in parameters by defining a new type and assigning to decls in that type. This partially works because Zig creates a new instantiation of the function for each different type passed as theanytype
argument. However, when the function has already been instantiated for the type passed, the type declaration inside the function is re-used, and the decls get overwritten. This affects thesimple_router
example in the repo, where/geta
,/getb
, and/inca
all share the sameself
type and thus share the same request handler.zap.Router
will have to find another way to pass theself
argument to the routing functions.