enum

    1. 1/8 test "enum ordinal value"...OK
    2. 2/8 test "set enum ordinal value"...OK
    3. 3/8 test "enum method"...OK
    4. 4/8 test "enum variant switch"...OK
    5. 5/8 test "@TagType"...OK
    6. 6/8 test "@memberCount"...OK
    7. 7/8 test "@memberName"...OK
    8. 8/8 test "@tagName"...OK
    9. All tests passed.

    See also:

    By default, enums are not guaranteed to be compatible with the C ABI:

    test.zig

    1. const Foo = enum { A, B, C };
    2. export fn entry(foo: Foo) void { }

    test.zig

    1. const Foo = extern enum { A, B, C };
    1. $ zig build-obj test.zig

    By default, the size of enums is not guaranteed.

    packed enum causes the size of the enum to be the same as the size of the integer tag type of the enum:

    1. $ zig test test.zig
    2. 1/1 test "packed enum"...OK
    3. All tests passed.

    This makes the enum eligible to be in a packed struct.

    Enum literals allow specifying the name of an enum field without specifying the enum type:

    test.zig

    1. const std = @import("std");
    2. const assert = std.debug.assert;
    3. const Color = enum {
    4. Auto,
    5. Off,
    6. };
    7. test "enum literals" {
    8. const color1: Color = .Auto;
    9. const color2 = Color.Auto;
    10. assert(color1 == color2);
    11. }
    12. test "switch using enum literals" {
    13. const color = Color.On;
    14. const result = switch (color) {
    15. .Auto => false,
    16. .On => true,
    17. .Off => false,
    18. };
    19. }