add reflection example

main
Jordan Orelli 4 years ago
parent 300c8b0c36
commit d8ea7fbd70

@ -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),
},
);
}
}
Loading…
Cancel
Save