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.

print

Allocates a formatted string which is returned on success.

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.

See std.Io.Writer.print.

Allocator.print
pub fn print(a: Allocator, comptime format: []const u8, args: anytype) Error![]u8

File

lib/std/mem/Allocator.zig:485

Code

pub fn print(a: Allocator, comptime format: []const u8, args: anytype) Error![]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.toOwnedSlice();
}