GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Durobot/zigStructPrint: Small library to pretty-print Zig structs (and arrays)

BranchesTags
Open more actions menu

Latest commit

 

History

8 Commits
8 Commits

Folders and files

NameName
Last commit message
Last commit date
src
src
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
build.zig
build.zig
 
 
build.zig.zon
build.zig.zon
 
 

Repository files navigation

zigStructPrint

Small library to pretty-print Zig structs (and arrays)

zigStructPrint is licensed under under the MIT License and available from https://github.com/Durobot/zigStructPrint

Please note that only Zig 0.14.0-dev.1421+f87dd43c1 (give or take) and up is supported because of this breaking change in the Zig standard library. If you need zigStructPrint for an earlier version of Zig, get this version instead.

To use, either drop zsp.zig into your project, or, if you prefer Zig package manager:

  1. In build.zig.zon, in .dependencies, add

    .zigStructPrint =
    .{
        .url = "https://github.com/Durobot/zigStructPrint/archive/<COMMIT HASH, 40 HEX DIGITS>.tar.gz",
        .hash = "<ZIG PACKAGE HASH, 68 HEX DIGITS>" // Use arbitrary hash, get correct hash from the error 
    }
  2. In build.zig, in pub fn build, before b.installArtifact(exe);, add

    const zsp = b.dependency("zigStructPrint",
    .{
        .target = target,
        .optimize = optimize,
    });
    exe.root_module.addImport("zigStructPrint", zsp.module("zigStructPrint"));

Build with zig build, as you normally do.

Actually printing out your struct:

const zsp = @import("zigStructPrint");
. . .
const MyStruct = struct
{
    a: i8 = -10,
    b: u32 = 10,
    c: [3]u8 = [_]u8 { 1, 2, 3 },
    d: [2]Nested = .{ .{ .f = 10.0, .g = "Hello" }, .{ .f = -20.0, .g = "Bye" }, },
    e: [3]Color = .{ .red, .green, .yellow },

    const Nested = struct { f: f32, g: []const u8 };
    const Color = enum { red, yellow, green };
};
const ms = MyStruct {};
zsp.printStruct(ms, true, 0); // try `false` to get full type names

And the output is:

{
    a: i8 = -10
    b: u32 = 10
    c: [3]u8 = [ 1, 2, 3, ]
    d: [2]Nested = [ { f: f32 = 10, g: []const u8 = "Hello", }, { f: f32 = -20, g: []const u8 = "Bye", }, ]
    e: [3]Color = [ red, green, yellow, ]
}

About

Small library to pretty-print Zig structs (and arrays)

Topics

zigzig-packageziglang

Resources

Readme
MIT license
Activity

Stars

1 star

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.