1const std = @import("std");
2const string = []const u8;
3const extras = @import("./lib.zig");
4
5pub fn isArrayOf(comptime T: type) fn (type) bool {
6 const Closure = struct {
7 pub fn trait(comptime C: type) bool {
8 return switch (@typeInfo(C)) {
9 .array => |ti| ti.child == T,
10 else => false,
11 };
12 }
13 };
14 return Closure.trait;
15}
16
17const L = isArrayOf(u8);
18test {
19 try std.testing.expect(L([5]u8));
20}
21test {
22 try std.testing.expect(!L([3]u32));
23}
24test {
25 try std.testing.expect(!L(struct { a: u8 }));
26}
27test {
28 try std.testing.expect(!L(enum { a, b, c }));
29}