#Access type of struct's field

1 messages · Page 1 of 1 (latest)

golden nexus
#

I'm looking to do something like this:

const Foo = struct {
    body: struct {
        name: []const u8,
        serial: ?[]const u8 = null,
        line: ?i32 = null,
        is_active: bool,
    },
};

const Bar = struct {
    body: @TypeOf(@field(Foo, "body")),
};

This of course doesn't work, but is there a way of doing this without creating a helper function which loops over the typeInfo fields and checks the name of every field in Foo?

leaden sail