I run into a lot of Zig code that uses @typeInfo
and this returns std.builtin.Type
I checked the documentation here Zig Documentation and would appreciate some clarification regarding some of the fields.
For Pointer
field
- It has a Size field, that can either be
One
,Many
,Slice
andC
so I am guessing this many, single item pointer, many item pointer, if it is a slice, C pointer. If so, the follow up question is, are there other properties on Pointer that have special meaning depending on what Size it is? - what does
is_const
andis_volatile
mean? - it has a
child: type
field. What does this mean? - What does
is_allowzero
mean? - What about
sentinel
? I was assuming this is meant to be the sentinel value that ends what is being pointed too…but I might be wrong
For ErrorSet
- What is the
error_set
in ErrorSet? - And then what is the payload?
Trying to investigate, I try this:
const error_set = error{One, Two};
std.debug.print("{any}", .{@typeInfo(@TypeOf(error_set))});
zig run src/main.zig
builtin.Type{ .Type = void }%
And the output I got is not what I was expecting. I thought it would be the ErrorSet
variant, but it is Type
which brings me to the next question.
For Type
- How come in
std.builtin.Type
there is also aType
variant? I mean is that not cyclical? But no, because the .Type is just void.
For NoReturn
- Not sure what kind of Type this refers to
For AnyFrame:
- Similar to NoReturn, not sure what kind of Type this refers to.
For Struct
- Basically not sure I understand any of the fields: layout, backing_integer, fields, decls, is_tuple. Fields I can guess to be the fields, while decls are the methods? But not sure about the rest.
Explanation of the above or a pointer to where I can read up on them would be appreciated.