1const std = @import("std");
2const string = []const u8;
3const extras = @import("./lib.zig");
4const expectSimilarType = extras.expectSimilarType;
5
6pub fn ReverseFields(comptime T: type) type {
7 const info = @typeInfo(T).@"struct";
8 const len = info.fields.len;
9 var names: [len][]const u8 = undefined;
10 var types: [len]type = undefined;
11 for (0..len) |i| {
12 names[i] = info.fields[len - 1 - i].name;
13 types[i] = info.fields[len - 1 - i].type;
14 }
15 return @Struct(info.layout, null, &names, &types, &@splat(.{}));
16}
17
18test {
19 try expectSimilarType(
20 ReverseFields(struct {
21 x: u8,
22 y: u16,
23 }),
24 struct {
25 y: u16,
26 x: u8,
27 },
28 );
29}