Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
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 standard library. Private Type Function

SliceTo

Private Type Function
std.mem.SliceTo
fn SliceTo(comptime T: type, comptime end: std.meta.Elem(T)) type

Helper for the return type of sliceTo()

File

mem.zig:943
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
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));
}