Function toOwnedSliceSentinel [src]

Prototype

pub fn toOwnedSliceSentinel(a: *Allocating, comptime sentinel: u8) Allocator.Error![:sentinel]u8

Parameters

a: *Allocatingsentinel: u8

Source

pub fn toOwnedSliceSentinel(a: *Allocating, comptime sentinel: u8) Allocator.Error![:sentinel]u8 { // This addition can never overflow because `a.writer.buffer` can never occupy the whole address space. try ensureTotalCapacityPrecise(a, a.writer.end + 1); a.writer.buffer[a.writer.end] = sentinel; a.writer.end += 1; errdefer a.writer.end -= 1; const result = try toOwnedSlice(a); return result[0 .. result.len - 1 :sentinel]; }