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
- Host: GitHub
- URL: https://github.com/Hejsil/fmtbuf
- Owner: Hejsil
- License: mit
- Archived: true
- Created: 2023-02-28T15:15:55.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-04-14T07:15:10.000Z (about 3 years ago)
- Last Synced: 2025-02-20T17:41:36.497Z (about 1 year ago)
- Topics: buffer, formatting, zig, zig-lib, zig-library, zig-package
- Language: Zig
- Homepage:
- Size: 7.81 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
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}));
}
```