diff options
Diffstat (limited to 'src/gss.zig')
| -rw-r--r-- | src/gss.zig | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/gss.zig b/src/gss.zig index ba8542d..8f81d80 100644 --- a/src/gss.zig +++ b/src/gss.zig @@ -4,7 +4,7 @@ pub fn Node(T: type) type { return struct { const Self = @This(); - parent: ?*Node = null, + parent: ?*Self = null, state: T, pub fn init(state: T) Self { @@ -18,7 +18,14 @@ pub fn Node(T: type) type { return node; } - pub fn pop(self: *Self, allocator: std.mem.Allocator) struct { T, *Self } { + pub fn clone(self: *Self, state: T, allocator: std.mem.Allocator) !*Self { + const node = try allocator.create(Self); + node.parent = self.parent; + node.state = state; + return node; + } + + pub fn pop(self: *Self, allocator: std.mem.Allocator) struct { T, ?*Self } { const parent = self.parent; const state = self.state; @@ -26,5 +33,17 @@ pub fn Node(T: type) type { return .{ state, parent }; } + + pub fn format( + self: *const Self, + comptime fmt: []const u8, + options: std.fmt.FormatOptions, + writer: anytype, + ) !void { + _ = fmt; + _ = options; + + try writer.print("Node {{ {} }}", .{ self.state }); + } }; } |