aboutsummaryrefslogtreecommitdiff
path: root/src/object.zig
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2025-08-30 15:49:18 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2025-08-30 15:49:18 +0200
commita46436e58beaaa322c082af5e886f96fd31d7a08 (patch)
tree05a05b149c2f18cb0562aef94fe41bd5aaad9fbc /src/object.zig
parent4feb8c7dab2b0a3492b8248ee12c3f0a475106f1 (diff)
Use mix-in design for interface abstraction.HEADmaster
Diffstat (limited to 'src/object.zig')
-rw-r--r--src/object.zig70
1 files changed, 0 insertions, 70 deletions
diff --git a/src/object.zig b/src/object.zig
deleted file mode 100644
index 7820674..0000000
--- a/src/object.zig
+++ /dev/null
@@ -1,70 +0,0 @@
-const std = @import("std");
-const wayland = @import("root.zig");
-
-const Self = @This();
-
-pub const Ref = struct {
- id: u32,
-
- pub const display: @This() = .{
- .id = 1,
- };
-
- pub const registry: @This() = .{
- .id = 2,
- };
-};
-
-const VTable = struct {
- on_event: *const fn (
- ptr: *anyopaque,
- ctx: wayland.Context,
- opcode: u16,
- args: []const u8,
- ) void,
-};
-
-ptr: ?*anyopaque,
-vtable: VTable,
-name: []const u8,
-
-pub inline fn on_event(
- self: *Self,
- ctx: wayland.Context,
- opcode: u16,
- args: []const u8,
-) !void {
- if (self.ptr) |ptr| {
- self.vtable.on_event(ptr, ctx, opcode, args);
- } else {
- return error.UseAfterRelease;
- }
-}
-
-pub inline fn from_self(ptr: anytype) Self {
- const T = @TypeOf(ptr.*);
-
- return .{
- .ptr = ptr,
- .vtable = VTable{
- .on_event = T.Events.on_event,
- },
- .name = @typeName(T),
- };
-}
-
-pub fn disable(self: *Self) void {
- self.ptr = null;
-}
-
-pub fn format(
- self: *const Self,
- comptime fmt: []const u8,
- options: std.fmt.FormatOptions,
- writer: anytype,
-) !void {
- _ = fmt;
- _ = options;
-
- try writer.print("Object<{s}> {{ {?} }}", .{self.name, self.ptr});
-}