From 987bd9323a384e8f042311262d9b0e0eba38da15 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Thu, 30 Apr 2026 14:33:13 +0200 Subject: refactor(html): generalize element creation --- src/eval/html/Root.zig | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'src/eval/html/Root.zig') diff --git a/src/eval/html/Root.zig b/src/eval/html/Root.zig index 440667a..83859d4 100644 --- a/src/eval/html/Root.zig +++ b/src/eval/html/Root.zig @@ -28,10 +28,7 @@ pub fn deinit(self: *Self) void { } pub fn element(self: *Self) Element { - return .{ .vtable = .{ - .render = render, - .node = getNode, - }, .ptr = self }; + return (Element.Wrapper(Self){ .ptr = self }).element(); } pub fn allocator(self: *Self) Allocator { @@ -42,18 +39,12 @@ pub fn append(self: *Self, el: Element) void { self.content.append(&el.node().node); } -fn getNode(context: *anyopaque) *Node { - const self: *Self = @ptrCast(@alignCast(context)); - return &self.node; -} - fn fromNode(context: *anyopaque) Element { const self: *Self = @ptrCast(@alignCast(context)); return self.element(); } -fn render(context: *anyopaque, alloc: Allocator) Error![]const u8 { - const self: *Self = @ptrCast(@alignCast(context)); +pub fn render(self: *Self, alloc: Allocator) Error![]const u8 { if (self.content.first == null) return ""; var acc = try std.ArrayList(u8).initCapacity(alloc, 8); errdefer acc.deinit(alloc); -- cgit v1.2.3