mod(layout/Stacks): add comptime checks for correct Element union typing
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 34s
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 34s
This commit is contained in:
@@ -19,8 +19,13 @@ pub fn Layout(comptime Event: type, comptime Element: type, comptime Renderer: t
|
||||
@compileError("Provided type `Element` for `Layout(comptime Event: type, comptime Element: type, comptime Renderer: type)` is not of type `union(enum)`.");
|
||||
}
|
||||
const Elements = std.ArrayList(Element);
|
||||
// TODO: expect name of field to be corresponding to the type
|
||||
if (!std.mem.eql(u8, @typeInfo(Element).Union.fields[0].name, "layout")) {
|
||||
@compileError("Expected `layout: Layout` to be the first union element, but has name: " ++ @typeInfo(Element).Union.fields[0].name);
|
||||
}
|
||||
const LayoutType = @typeInfo(Element).Union.fields[0].type;
|
||||
if (!std.mem.eql(u8, @typeInfo(Element).Union.fields[1].name, "widget")) {
|
||||
@compileError("Expected `widget: Widget` to be the first union element, but has name: " ++ @typeInfo(Element).Union.fields[1].name);
|
||||
}
|
||||
const WidgetType = @typeInfo(Element).Union.fields[1].type;
|
||||
const Events = std.ArrayList(Event);
|
||||
return struct {
|
||||
|
||||
@@ -19,8 +19,13 @@ pub fn Layout(comptime Event: type, comptime Element: type, comptime Renderer: t
|
||||
@compileError("Provided type `Element` for `Layout(comptime Event: type, comptime Element: type, comptime Renderer: type)` is not of type `union(enum)`.");
|
||||
}
|
||||
const Elements = std.ArrayList(Element);
|
||||
// TODO: expect name of field to be corresponding to the type
|
||||
if (!std.mem.eql(u8, @typeInfo(Element).Union.fields[0].name, "layout")) {
|
||||
@compileError("Expected `layout: Layout` to be the first union element, but has name: " ++ @typeInfo(Element).Union.fields[0].name);
|
||||
}
|
||||
const LayoutType = @typeInfo(Element).Union.fields[0].type;
|
||||
if (!std.mem.eql(u8, @typeInfo(Element).Union.fields[1].name, "widget")) {
|
||||
@compileError("Expected `widget: Widget` to be the first union element, but has name: " ++ @typeInfo(Element).Union.fields[1].name);
|
||||
}
|
||||
const WidgetType = @typeInfo(Element).Union.fields[1].type;
|
||||
const Events = std.ArrayList(Event);
|
||||
return struct {
|
||||
|
||||
Reference in New Issue
Block a user