Given a "memory span" type, returns the same type except with the given sentinel value.
pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type
pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {
switch (@typeInfo(T)) {
.pointer => |info| switch (info.size) {
.one => switch (@typeInfo(info.child)) {
.array => |array_info| return @Pointer(
.one,
info.attrs,
[array_info.len:sentinel_val]array_info.child,
null,
),
else => {},
},
.many, .slice => |size| return @Pointer(size, info.attrs, info.child, sentinel_val),
else => {},
},
.optional => |info| switch (@typeInfo(info.child)) {
.pointer => |ptr_info| switch (ptr_info.size) {
.many => return ?@Pointer(.many, ptr_info.attrs, ptr_info.child, sentinel_val),
else => {},
},
else => {},
},
else => {},
}
@compileError("Unable to derive a sentinel pointer type from " ++ @typeName(T));
}