Hacker News new | past | comments | ask | show | jobs | submit login

`@bitCast` addresses this use case:

    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,
    };



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: