@pkmn/engine 0.1.0-dev.46307385 → 0.1.0-dev.4cc7c5c2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,6 +14,7 @@ pub fn Optional(comptime T: type) type {
14
14
  var decls = [_]std.builtin.Type.Declaration{};
15
15
 
16
16
  enumFields[0] = .{ .name = "None", .value = 0 };
17
+
17
18
  inline for (fields, 1..) |field, i| {
18
19
  assert(!std.mem.eql(u8, field.name, "None"));
19
20
  enumFields[i] = .{
@@ -24,7 +25,7 @@ pub fn Optional(comptime T: type) type {
24
25
 
25
26
  return @Type(.{
26
27
  .Enum = .{
27
- .tag_type = std.math.IntFittingRange(0, fields.len + 1),
28
+ .tag_type = std.math.IntFittingRange(0, fields.len),
28
29
  .fields = &enumFields,
29
30
  .decls = &decls,
30
31
  .is_exhaustive = true,
@@ -57,4 +58,10 @@ test Optional {
57
58
  try expect(q == .None);
58
59
  try expect(q != .P1);
59
60
  try expect(q != .P2);
61
+
62
+ const Three = enum(u2) { A, B, C };
63
+ try expect(@bitSizeOf(Optional(Three)) == 2);
64
+
65
+ const Four = enum(u2) { A, B, C, D };
66
+ try expect(@bitSizeOf(Optional(Four)) == 3);
60
67
  }