Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

Sentinel

Given a "memory span" type, returns the same type except with the given sentinel value.

meta.Sentinel
pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type

File

lib/std/meta.zig:144

Code

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));
}