diff options
| author | Nic Gaffney <gaffney_nic@protonmail.com> | 2025-10-21 00:09:07 -0500 |
|---|---|---|
| committer | Nic Gaffney <gaffney_nic@protonmail.com> | 2025-10-21 00:09:07 -0500 |
| commit | c034b4a1291a803028eef8b0950a7090ea54b047 (patch) | |
| tree | 987040745c887299e69f2c3014c44ea829d89bb3 /src/util.zig | |
| parent | b4588b2064c3afde9497084caef6e83246b32501 (diff) | |
| download | funcz-c034b4a1291a803028eef8b0950a7090ea54b047.tar.gz | |
Currying, Combinators, and organization
Diffstat (limited to 'src/util.zig')
| -rw-r--r-- | src/util.zig | 16 |
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; +} |
