diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2026-04-30 17:56:55 +0200 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2026-04-30 17:56:55 +0200 |
| commit | a13df3ca580dc31544ef092d5d37e18089af3517 (patch) | |
| tree | cfcf8c1d8322ee8e97783e263105eac9f5c00f33 /src/eval/html/Element.zig | |
| parent | 5ecd48d4b9f928beb4143f88e802ee4d9e25a2bd (diff) | |
refactor(element): generalize element creation
Diffstat (limited to 'src/eval/html/Element.zig')
| -rw-r--r-- | src/eval/html/Element.zig | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/eval/html/Element.zig b/src/eval/html/Element.zig index 52ee58d..dd24bea 100644 --- a/src/eval/html/Element.zig +++ b/src/eval/html/Element.zig @@ -11,13 +11,12 @@ pub const Root = @import("Root.zig"); pub const Error = html.Error || Allocator.Error; -pub fn Wrapper(comptime V: type) type { +pub fn Wrapper(comptime V: type, comptime r: *const fn (*V, Allocator) Error![]const u8) type { comptime { if (!@hasField(V, "node")) @compileError("missing field 'node' for " ++ @typeName(V)); const nd = @FieldType(V, "node"); if (nd != Node) @compileError("invalid node's type: " ++ @typeName(nd) ++ ", want " ++ @typeName(Node)); if (!std.meta.hasMethod(V, "element")) @compileError("missing declaration 'element' for " ++ @typeName(V)); - if (!std.meta.hasMethod(V, "render")) @compileError("missing declaration 'render' for " ++ @typeName(V)); } return struct { ptr: *V, @@ -31,7 +30,11 @@ pub fn Wrapper(comptime V: type) type { fn render(context: *anyopaque, alloc: Allocator) Error![]const u8 { const self: *V = @ptrCast(@alignCast(context)); - return try self.render(alloc); + return try r(self, alloc); + } + + pub fn init(ptr: *V) Element { + return (Self{ .ptr = ptr }).element(); } pub fn element(self: Self) Element { |
