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. Public Function

printSentinel

Public Function
std.mem.Allocator.printSentinel
pub fn printSentinel(
    a: Allocator,
    comptime format: []const u8,
    args: anytype,
    comptime sentinel: u8,
) Allocator.Error![:sentinel]u8

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.

Params

  • a: Allocator
  • format: []const u8
  • args
  • sentinel: u8

File

mem/Allocator.zig:510
510
511
512
513
514
515
516
517
518
519
520
521
522
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);
}