From c034b4a1291a803028eef8b0950a7090ea54b047 Mon Sep 17 00:00:00 2001 From: Nic Gaffney Date: Tue, 21 Oct 2025 00:09:07 -0500 Subject: Currying, Combinators, and organization --- src/util.zig | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/util.zig (limited to 'src/util.zig') diff --git a/src/util.zig b/src/util.zig new file mode 100644 index 0000000..8de989e --- /dev/null +++ b/src/util.zig @@ -0,0 +1,16 @@ +const std = @import("std"); +const Type = std.builtin.Type; + +pub fn typeVerify(T: type, expected: anytype) Type { + const expectedType = @TypeOf(expected); + const expectedTypeInfo = @typeInfo(expectedType); + if (expectedTypeInfo != .@"struct") + @compileError("Expected struct or tuple, found " ++ @typeName(expectedType)); + const realTypeInfo = @typeInfo(T); + for (expected) |e| { + if(realTypeInfo == e) return realTypeInfo; + } + for (expected) |e| + @compileError("Expected one of " ++ @tagName(e) ++ ", found " ++ @typeName(T)); + return realTypeInfo; +} -- cgit v1.2.3