A format utility for quick custom formatting in Zig. zig@0.15.2.
const Example = struct {
a: u8,
b: u16, // as hex
c: bool, // skipped
d: []u8, // str
pub const format = formatWithHint(@This(), .{ .b = "0x{X}", .d = .str, .c = .skip});
};
formatWithHint. Creates a fmt function, changing the behaviour of matching fields. Value args follow…<fn>: calls the fn like a format procedure for that field.<ptr>: assumption is a format string, concat and use..skip: skips and doesn’t print the field..skip_noted: skips printing out the value but still notes the existence of the field. E.g..field_name = ⋯..str: Anything string like gets formatted with"{s}"..fixed_c_str: C-like string that can be passed tostd.mem.sliceTo(str, 0)prior to"{s}"..flags: Prints out enabled fields in a flag struct (struct with justbools). Skips non bool fields..unix_time: An int that is convertible into astd.posix.time_t, Print an 8601 like date-time.libcrequired.
time8601Format. Prints out a 8601 like time-date from a Linux epoch.[2025-11-12T17:51:05].libcrequired.flagsFormat. Prints out enabled fields in a flag struct (struct with justbools). Skips non bool fields.HexDump. Prints out a formatted hex dump from the providedu8slice.
Add to your build.zig.zon…
zig fetch --save git+https://codeberg.org/MinervasRefuge/Lesser-Format
Add to your build.zig…
const dependency_lesser_fmt = b.dependency("LesserFormat", .{
.target = target,
.optimize = optimise,
.link_libc = true, // or `false` if time printing isn't needed
});
your_module.addImport("Lesser-Format", dependency_lesser_fmt.module("Lesser-Format"));
BSD-3-Clause : Copyright © 2025 Abigale Raeck.