From 8171972cbb477672ee1a99d953df4aaecb744a0c Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Mon, 23 May 2022 20:58:13 +1200 Subject: [PATCH] document bufPrint, and format now uses `writer` not `output` --- lib/std/fmt.zig | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig index 64351088f5..54b68572b5 100644 --- a/lib/std/fmt.zig +++ b/lib/std/fmt.zig @@ -24,9 +24,9 @@ pub const FormatOptions = struct { fill: u8 = ' ', }; -/// Renders fmt string with args, calling output with slices of bytes. -/// If `output` returns an error, the error is returned from `format` and -/// `output` is not called again. +/// Renders fmt string with args, calling `writer` with slices of bytes. +/// If `writer` returns an error, the error is returned from `format` and +/// `writer` is not called again. /// /// The format string must be comptime known and may contain placeholders following /// this format: @@ -1869,6 +1869,9 @@ pub const BufPrintError = error{ /// As much as possible was written to the buffer, but it was too small to fit all the printed bytes. NoSpaceLeft, }; + +/// print a Formatter string into `buf`. Actually just a thin wrapper around `format` and `fixedBufferStream`. +/// returns a slice of the bytes printed to. pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: anytype) BufPrintError![]u8 { var fbs = std.io.fixedBufferStream(buf); try format(fbs.writer(), fmt, args);