aboutsummaryrefslogtreecommitdiff
path: root/src/util.zig
blob: 8de989ef518501df3d2f8fa5501a187dadc104f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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;
}