One area where this is still less flexible than regular bit masking is that quite often I want to access groups of bits as a value. For instance if the bits represent in/out pins on a chip emulator, sometimes I want to access unique data bus pins, and sometimes I want to set or get the data bus value. Maybe Zig can handle this case with unions though, I haven't tried this yet (this would require that unions can work…
const std = @import("std");
const expect = std.testing.expect;
test {
const group1: P = .{ .a = true, .b = true };
const group2: P = .{ .c = true };
const group3 = @bitCast(P, @bitCast(u4, group1) | @bitCast(u4, group2));
try expect(group3.a);
try expect(group3.b);
try expect(group3.c);
try expect(!group3.d);
}
const P = packed struct {
a: bool = false,
b: bool = false,
c: bool = false,
d: bool = false,
};