utils.zig (661B)
1 const std = @import("std"); 2 3 pub fn NewType(comptime IntType_: type, comptime DummyType: type) type { 4 return enum(IntType_) { 5 root = 0, 6 _, 7 8 const Self = @This(); 9 pub const Int = IntType_; 10 const _DummyType = DummyType; 11 12 pub fn next(self: @This()) ?@This() { 13 if (@intFromEnum(self) == std.math.maxInt(IntType_)) 14 return null; 15 return @enumFromInt(@intFromEnum(self) + 1); 16 } 17 18 pub fn format(self: @This(), comptime _: []const u8, _: anytype, writer: anytype) !void { 19 try writer.print("@enumFromInt({})", .{@intFromEnum(self)}); 20 } 21 }; 22 }