Is anyone aware of a method to access packed struct fields based on a runtime index? Essentially replicating in a roundabout manner what field access of a “packed array” might look like.
Context: must work with very large (backed by u16448) packed structs that contain multiple order-dependent repeated fields. Think of, for an example, a packed struct that contains a status bit for every potentially connected device in the fashion:
device1_connected: bool,
device2_connected: bool,
…
device150_connected: bool,
Current (tedious) solution is to create a function for every field:
deviceConnected(self: MyPackedStruct, devno: u8) bool {
return switch (devno) {
0 => self.device1_connected,
…
149 => self.device150_connected,
else => unreachable,
};
}
Edit:
Packed struct fields can also be nested packed structs, such as:
device1_connected: packed struct(u2) {
left: bool,
right: bool,
}