mirror of
https://github.com/ziglang/zig.git
synced 2025-12-14 02:03:08 +00:00
19 lines
442 B
Zig
19 lines
442 B
Zig
const std = @import("std");
|
|
const Type = std.builtin.Type;
|
|
|
|
test "Tuple" {
|
|
const fields_list = fields(@TypeOf(.{}));
|
|
if (fields_list.len != 0)
|
|
@compileError("Argument count mismatch");
|
|
}
|
|
|
|
pub fn fields(comptime T: type) switch (@typeInfo(T)) {
|
|
.Struct => []const Type.StructField,
|
|
else => unreachable,
|
|
} {
|
|
return switch (@typeInfo(T)) {
|
|
.Struct => |info| info.fields,
|
|
else => unreachable,
|
|
};
|
|
}
|