DoxigAlpha

initSubtype

Function parameters

Parameters

#
self:*const DevicePath
TUnion:type

Type definitions in this namespace

Types

#

Source

Implementation

#
pub fn initSubtype(self: *const DevicePath, comptime TUnion: type) ?TUnion {
    const type_info = @typeInfo(TUnion).@"union";
    const TTag = type_info.tag_type.?;

    inline for (type_info.fields) |subtype| {
        // The tag names match the union names, so just grab that off the enum
        const tag_val: u8 = @intFromEnum(@field(TTag, subtype.name));

        if (self.subtype == tag_val) {
            // e.g. expr = .{ .pci = @ptrCast(...) }
            return @unionInit(TUnion, subtype.name, @as(subtype.type, @ptrCast(self)));
        }
    }

    return null;
}