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.

absorbSentinel

If the provided slice is not sentinel terminated, do nothing and return that slice. If it is sentinel-terminated, return a non-sentinel-terminated slice with the length increased by one to include the absorbed sentinel element.

mem.absorbSentinel
pub fn absorbSentinel(slice: anytype) AbsorbSentinelReturnType(@TypeOf(slice))

File

lib/std/mem.zig:4718

Code

pub fn absorbSentinel(slice: anytype) AbsorbSentinelReturnType(@TypeOf(slice)) {
    const info = @typeInfo(@TypeOf(slice)).pointer;
    comptime assert(info.size == .slice);
    if (info.sentinel_ptr == null) {
        return slice;
    } else {
        return slice.ptr[0 .. slice.len + 1];
    }
}