#If zig files are structs, can they ever be an enum?

1 messages · Page 1 of 1 (latest)

rotund pendant
#

Ive discovered you can make single struct files using @This() and other nice syntax. which allows importing directly like const MyStruct = @import("MyStruct.zig")
Im curious if theres any syntax that allows the same sort of thing, but with enums, where a file can be an enum, and get directly imported as such?

coarse urchin
#

nope. they can only be structs
:|

rotund pendant
#

sad days.
suppose i can always approximate an enum with a struct haha

#

ty for v fast answer!

#

for anyone in the future this is my workaround for a struct called layer, which defines a z index:

pub const Layer = struct {
    z_index: i32,
};

fn layer(z_index: i32) Layer {
    return .{
        .z_index = z_index
    };
}

pub const FLOOR = layer(0);
pub const ENTITIES = layer(1);
little holly
#

imo it's better to just declare a pub global enum in your file, and import it like @import("./Foo.zig").Foo