diff --git a/reflection.zig b/reflection.zig new file mode 100644 index 0000000..30f0a20 --- /dev/null +++ b/reflection.zig @@ -0,0 +1,24 @@ +const std = @import("std"); + +const Header = struct { + magic: u32, + name: []const u8, +}; + +pub fn main() void { + printInfoAboutStruct(Header); +} + +fn printInfoAboutStruct(comptime T: type) void { + const info = @typeInfo(T); + inline for (info.Struct.fields) |field| { + std.debug.print( + "{} has field called {} with type {}\n", + .{ + @typeName(T), + field.name, + @typeName(field.field_type), + }, + ); + } +}