Dealing with complex typed values

I’m using the zig-sqlite library and was considering storing away some “prepared statements” in a context structure for reuse. I couldn’t figure out how to declare the type of the struct field since the type itself seems to use the sql statement string.

While I’ll eventually figure it out, I have a broader question - how do we do this in the general case … where the type of a value is determined by some complex comptime computation tucked away inside a library?

If you don’t know the type of something, then @compileLog() can help you figure it out .
For example if this is returned from a function you can just do @compileLog(@TypeOf(thingThatReturnsTheType())).
If even with this you cannot figure out how to actually access the type, you can just use @TypeOf() in the type declaration:
field: @TypeOf(...),

3 Likes