const std = @import("std"); pub fn Node(T: type) type { return struct { const Self = @This(); parent: ?*Node = null, state: T, pub fn init(state: T) Self { return Self { .state = state }; } pub fn push(self: *Self, state: T, allocator: std.mem.Allocator) !*Self { const node = try allocator.create(Self); node.parent = self; 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; allocator.destroy(self); return .{ state, parent }; } }; }