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