#create struct field based on comptime input

1 messages · Page 1 of 1 (latest)

worthy heron
#

It's possible to add fields to a struct based on some comptime data?

pub fn createStruct(x: anytype) type {
return struct {
// ?????
}
}

I expect the createStruct(.{"a", u8, "b", u16}) to be something like:
struct {
a: u8,
b: u16
}

In the example doesn't make so much sense, but my idea is iterate over some enum/union fields and create fields for each one. Similar to MultiArrayList, but I found MultiArrayList really annoying.

calm verge
#

you can do so with the @Type builtin but note that any type made using this cant have decls