authorgravatar for dominic.tarr@gmail.comDominic Tarr <dominic.tarr@gmail.com> 2022-05-23 20:58:13+12:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-05-23 11:58:13+03:00
log8171972cbb477672ee1a99d953df4aaecb744a0c
treeaca3f798a3a1e8ed0e8944feca7419438ff8a7f8
parent64de32b34127df819322b91bc7643a0eb392d499
signature Signed by PGP key 4AEE18F83AFDEB23

document bufPrint, and format now uses `writer` not `output`


1 files changed, 6 insertions(+), 3 deletions(-)

lib/std/fmt.zig+6-3
......@@ -24,9 +24,9 @@ pub const FormatOptions = struct {
2424 fill: u8 = ' ',
2525};
2626
27/// Renders fmt string with args, calling output with slices of bytes.
28/// If `output` returns an error, the error is returned from `format` and
29/// `output` is not called again.
27/// Renders fmt string with args, calling `writer` with slices of bytes.
28/// If `writer` returns an error, the error is returned from `format` and
29/// `writer` is not called again.
3030///
3131/// The format string must be comptime known and may contain placeholders following
3232/// this format:
......@@ -1869,6 +1869,9 @@ pub const BufPrintError = error{
18691869 /// As much as possible was written to the buffer, but it was too small to fit all the printed bytes.
18701870 NoSpaceLeft,
18711871};
1872
1873/// print a Formatter string into `buf`. Actually just a thin wrapper around `format` and `fixedBufferStream`.
1874/// returns a slice of the bytes printed to.
18721875pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: anytype) BufPrintError![]u8 {
18731876 var fbs = std.io.fixedBufferStream(buf);
18741877 try format(fbs.writer(), fmt, args);