Skip to content

A format utility for quick custom formatting in Zig.

License

Notifications You must be signed in to change notification settings

MinervasRefuge/Lesser-Format

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lesser-Format

https://ko-fi.com/img/githubbutton_sm.svg


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});
};

API

  • 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 to std.mem.sliceTo(str, 0) prior to "{s}".
    • .flags : Prints out enabled fields in a flag struct (struct with just bool s). Skips non bool fields.
    • .unix_time : An int that is convertible into a std.posix.time_t, Print an 8601 like date-time. libc required.
  • time8601Format. Prints out a 8601 like time-date from a Linux epoch. [2025-11-12T17:51:05]. libc required.
  • flagsFormat. Prints out enabled fields in a flag struct (struct with just bool s). Skips non bool fields.
  • HexDump. Prints out a formatted hex dump from the provided u8 slice.

Project Usage

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.

About

A format utility for quick custom formatting in Zig.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Languages