1const std = @import("std");
2const string = []const u8;
3const extras = @import("./lib.zig");
4
5pub fn hasFields(comptime T: type, comptime names: anytype) bool {
6 inline for (names) |name| {
7 if (!@hasField(T, name))
8 return false;
9 }
10 return true;
11}
12
13test "hasFields" {
14 const TestStruct1 = struct {};
15 const TestStruct2 = struct {
16 a: u32,
17 b: u32,
18 c: bool,
19 pub fn useless() void {}
20 };
21
22 const tuple = .{ "a", "b", "c" };
23
24 try std.testing.expect(!hasFields(TestStruct1, .{"a"}));
25 try std.testing.expect(hasFields(TestStruct2, .{ "a", "b" }));
26 try std.testing.expect(hasFields(TestStruct2, .{ "a", "b", "c" }));
27 try std.testing.expect(hasFields(TestStruct2, tuple));
28 try std.testing.expect(!hasFields(TestStruct2, .{ "a", "b", "useless" }));
29}