Helper for the return type of sliceTo()
fn SliceTo(comptime T: type, comptime end: std.meta.Elem(T)) type
fn SliceTo(comptime T: type, comptime end: std.meta.Elem(T)) type {
switch (@typeInfo(T)) {
.optional => |optional_info| {
return ?SliceTo(optional_info.child, end);
},
.pointer => |ptr_info| {
const Elem = std.meta.Elem(T);
const have_sentinel: bool = switch (ptr_info.size) {
.one, .slice => if (std.meta.sentinel(T)) |s| s == end else false,
.many => if (std.meta.sentinel(T)) |s| s == end else true,
.c => true,
};
var attrs = ptr_info.attrs;
attrs.@"allowzero" = attrs.@"allowzero" and ptr_info.size != .c;
return @Pointer(.slice, attrs, Elem, if (have_sentinel) end else null);
},
else => {},
}
@compileError("invalid type given to std.mem.sliceTo: " ++ @typeName(T));
}