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

Span

Private Type Function
std.mem.Span
fn Span(comptime T: type) type

Takes a sentinel-terminated pointer and returns a slice preserving pointer attributes. [*c] pointers are assumed to be 0-terminated and assumed to not be allowzero.

File

mem.zig:882
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
fn Span(comptime T: type) type {
    switch (@typeInfo(T)) {
        .optional => |optional_info| {
            return ?Span(optional_info.child);
        },
        .pointer => |ptr_info| {
            const new_sentinel: ?ptr_info.child = switch (ptr_info.size) {
                .one, .slice => @compileError("invalid type given to std.mem.span: " ++ @typeName(T)),
                .many => ptr_info.sentinel() orelse @compileError("invalid type given to std.mem.span: " ++ @typeName(T)),
                .c => 0,
            };
            var attrs = ptr_info.attrs;
            attrs.@"allowzero" = attrs.@"allowzero" and ptr_info.size != .c;
            return @Pointer(.slice, attrs, ptr_info.child, new_sentinel);
        },
        else => {},
    }
    @compileError("invalid type given to std.mem.span: " ++ @typeName(T));
}