authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-01-11 02:44:11 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-01-11 02:44:11 -08:00
log671e2bd52fe822c66aa002f51d00c1919f20c61d
tree4680ed9547e8b36ff5fbf1867db16156bcb0c81e
parent4d76a93f5ec7c354beb7ed237a94d17bc0c8581a

isSlice: match pointer-to-array


1 files changed, 6 insertions(+), 1 deletions(-)

src/isSlice.zig+6-1
...@@ -4,7 +4,8 @@ const extras = @import("./lib.zig");...@@ -4,7 +4,8 @@ const extras = @import("./lib.zig");
44
5pub fn isSlice(comptime T: type) bool {5pub fn isSlice(comptime T: type) bool {
6 if (comptime is(.Pointer)(T)) {6 if (comptime is(.Pointer)(T)) {
7 return @typeInfo(T).Pointer.size == .Slice;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;
8 }9 }
9 return false;10 return false;
10}11}
...@@ -25,3 +26,7 @@ test {...@@ -25,3 +26,7 @@ test {
25 try std.testing.expect(!isSlice(@TypeOf(array)));26 try std.testing.expect(!isSlice(@TypeOf(array)));
26 try std.testing.expect(!isSlice(@TypeOf(&array[0])));27 try std.testing.expect(!isSlice(@TypeOf(&array[0])));
27}28}
29
30test {
31 try std.testing.expect(isSlice(@TypeOf(&[_]u32{ 66, 81, 99, 24, 36, 65, 24, 19, 25, 44 })));
32}