Like print but returned slice has the provided sentinel.
Returned slice can be deallocated with free. If an arena-style allocator
is used instead, such as std.heap.ArenaAllocator, then no call to free
is necessary. Illegal behavior occurs if the returned slice is type-coerced
to a slice without the sentinel and then passed to free.
pub fn printSentinel(
a: Allocator,
comptime format: []const u8,
args: anytype,
comptime sentinel: u8,
) Allocator.Error![:sentinel]u8
pub fn printSentinel(
a: Allocator,
comptime format: []const u8,
args: anytype,
comptime sentinel: u8,
) Allocator.Error![:sentinel]u8 {
var aw = try std.Io.Writer.Allocating.initCapacity(a, format.len);
defer aw.deinit();
aw.writer.print(format, args) catch |err| switch (err) {
error.WriteFailed => return error.OutOfMemory,
};
return aw.toOwnedSliceSentinel(sentinel);
}