Zig NEWS

Discussion on: Testing and Files as Structs

Collapse
 
deltomix profile image
DelTomix

Super helpful to see both an actual example of "zig imports files as structs" and a clear concise zig implementation of a familiar data structure.

The @import documentation mentions "Zig source files are implicitly structs" but its great to see an actual example!

Except (correct me if I'm wrong) with the bare struct contents separated into Node.zig - "Node" no longer has a declaration as the type, so for that to work wouldn't Node.zig then need to become;

data: u8,
left: ?*@This(),
right: ?*@This(),
Enter fullscreen mode Exit fullscreen mode

Or, with a 'Self' element and also using your defaults example;

const Self = @This();
data: u8,
left: ?*Self = null,
right: ?*Self = null,
Enter fullscreen mode Exit fullscreen mode

Also on that final main.zig snippet I found I needed to include the file name extension in the @import target;

const Node = @import("Node.zig");
Enter fullscreen mode Exit fullscreen mode

Wondering if maybe I should have done something in the generated build.zig ?

Collapse
 
aryaelfren profile image
Arya-Elfren

Thanks for the feedback! I fixed some of the things you pointed out.

I finally got around to compiling all the code and the final working stuff should be on the GitHub linked in the second post.