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
signaturebadge-question-mark 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 {...@@ -24,9 +24,9 @@ pub const FormatOptions = struct {
24 fill: u8 = ' ',24 fill: u8 = ' ',
25};25};
2626
27/// Renders fmt string with args, calling output with slices of bytes.27/// Renders fmt string with args, calling `writer` with slices of bytes.
28/// If `output` returns an error, the error is returned from `format` and28/// If `writer` returns an error, the error is returned from `format` and
29/// `output` is not called again.29/// `writer` is not called again.
30///30///
31/// The format string must be comptime known and may contain placeholders following31/// The format string must be comptime known and may contain placeholders following
32/// this format:32/// this format:
...@@ -1869,6 +1869,9 @@ pub const BufPrintError = error{...@@ -1869,6 +1869,9 @@ pub const BufPrintError = error{
1869 /// As much as possible was written to the buffer, but it was too small to fit all the printed bytes.1869 /// As much as possible was written to the buffer, but it was too small to fit all the printed bytes.
1870 NoSpaceLeft,1870 NoSpaceLeft,
1871};1871};
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.
1872pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: anytype) BufPrintError![]u8 {1875pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: anytype) BufPrintError![]u8 {
1873 var fbs = std.io.fixedBufferStream(buf);1876 var fbs = std.io.fixedBufferStream(buf);
1874 try format(fbs.writer(), fmt, args);1877 try format(fbs.writer(), fmt, args);