An open API service indexing awesome lists of open source software.

https://github.com/Hejsil/fmtbuf

Buffered formatting that figures out the buffer size for you
https://github.com/Hejsil/fmtbuf

buffer formatting zig zig-lib zig-library zig-package

Last synced: about 1 year ago
JSON representation

Buffered formatting that figures out the buffer size for you

Awesome Lists containing this project

README

          

# fmtbuf

An alternative to `std.fmt.bufPrintZ` which can:

* Automatically figure out the buffer size at compile time
* Can be partially formatted, allowing for a prefix to be formatted and reused.

```zig
const FmtBuf = @import("fmtbuf").FmtBuf;
const std = @import("std");

test {
var buf = FmtBuf("[{}] = {}", std.meta.Tuple(&.{ usize, u8 })){};
try std.testing.expectEqualStrings("[0] = 0", buf.format(.{ 0, 0 }));
try std.testing.expectEqualStrings("[12] = 3", buf.format(.{ 12, 3 }));

var partial = buf.partialFormat(1, .{500});
try std.testing.expectEqualStrings("[500] = 0", partial.format(.{0}));
try std.testing.expectEqualStrings("[500] = 1", partial.format(.{1}));
try std.testing.expectEqualStrings("[500] = 2", partial.format(.{2}));
}

```