Type id comptime generation

Hi and welcome to the forum!

Here’s one approach: https://github.com/ziglang/zig/issues/19858#issuecomment-2369861301

The code from that comment:

const TypeId = *const struct {
    _: u8,
};

pub inline fn typeId(comptime T: type) TypeId {
    return &struct {
        comptime {
            _ = T;
        }
        var id: @typeInfo(TypeId).pointer.child = undefined;
    }.id;
}
2 Likes