aboutsummaryrefslogtreecommitdiff
path: root/src/util.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.zig')
-rw-r--r--src/util.zig16
1 files changed, 16 insertions, 0 deletions
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;
+}