1const std = @import("std");
2const string = []const u8;
3const extras = @import("./lib.zig");
4
5pub fn isSlice(comptime T: type) bool {
6 if (comptime is(.pointer)(T)) {
7 if (@typeInfo(T).pointer.size == .slice) return true;
8 if (@typeInfo(T).pointer.size == .one and is(.array)(std.meta.Child(T))) return true;
9 }
10 return false;
11}
12fn is(comptime id: std.builtin.TypeId) fn (type) bool {
13 const Closure = struct {
14 pub fn trait(comptime T: type) bool {
15 return id == @typeInfo(T);
16 }
17 };
18 return Closure.trait;
19}
20
21test {
22 const array = [_]u8{0} ** 10;
23 var runtime_zero: usize = 0;
24 _ = &runtime_zero;
25 try std.testing.expect(isSlice(@TypeOf(array[runtime_zero..])));
26 try std.testing.expect(!isSlice(@TypeOf(array)));
27 try std.testing.expect(!isSlice(@TypeOf(&array[0])));
28}
29
30test {
31 try std.testing.expect(isSlice(@TypeOf(&[_]u32{ 66, 81, 99, 24, 36, 65, 24, 19, 25, 44 })));
32}