Function sentinel [src]
Given a type which can have a sentinel e.g. [:0]u8, returns the sentinel value,
or null if there is not one.
Types which cannot possibly have a sentinel will be a compile error.
Result is always comptime-known.
Prototype
pub inline fn sentinel(comptime T: type) ?Elem(T)
Parameters
T: type
Example
test sentinel {
try testSentinel();
try comptime testSentinel();
}
Source
pub inline fn sentinel(comptime T: type) ?Elem(T) {
switch (@typeInfo(T)) {
.array => |info| return info.sentinel(),
.pointer => |info| {
switch (info.size) {
.many, .slice => return info.sentinel(),
.one => switch (@typeInfo(info.child)) {
.array => |array_info| return array_info.sentinel(),
else => {},
},
else => {},
}
},
else => {},
}
@compileError("type '" ++ @typeName(T) ++ "' cannot possibly have a sentinel");
}