mod(dispatch): use anyopague instead of usize for pointer handling
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Has been cancelled

This commit is contained in:
2024-11-16 19:08:22 +01:00
parent 7c9038fbda
commit 4ef9e077cb
2 changed files with 10 additions and 12 deletions

View File

@@ -25,7 +25,6 @@ pub fn Layout(comptime Event: type, comptime Renderer: type) type {
layout: LayoutType,
widget: @import("widget.zig").Widget(Event, Renderer),
};
const Ptr = usize;
pub const Interface = @import("interface").Interface(.{
.handle = fn (anytype, Event) anyerror!*Events,
.render = fn (anytype, *Renderer) anyerror!void,
@@ -38,7 +37,7 @@ pub fn Layout(comptime Event: type, comptime Renderer: type) type {
deinit: *const fn (this: *LayoutType) void,
};
object: Ptr = undefined,
object: *anyopaque = undefined,
vtable: *const VTable = undefined,
// Handle the provided `Event` for this `Layout`.
@@ -58,25 +57,25 @@ pub fn Layout(comptime Event: type, comptime Renderer: type) type {
pub fn createFrom(object: anytype) LayoutType {
return LayoutType{
.object = @intFromPtr(object),
.object = @ptrCast(@alignCast(object)),
.vtable = &.{
.handle = struct {
// Handle the provided `Event` for this `Layout`.
fn handle(this: *LayoutType, event: Event) !*Events {
const layout: @TypeOf(object) = @ptrFromInt(this.object);
const layout: @TypeOf(object) = @ptrCast(@alignCast(this.object));
return try layout.handle(event);
}
}.handle,
.render = struct {
// Render the contents of this `Layout`.
fn render(this: *LayoutType, renderer: *Renderer) !void {
const layout: @TypeOf(object) = @ptrFromInt(this.object);
const layout: @TypeOf(object) = @ptrCast(@alignCast(this.object));
try layout.render(renderer);
}
}.render,
.deinit = struct {
fn deinit(this: *LayoutType) void {
const layout: @TypeOf(object) = @ptrFromInt(this.object);
const layout: @TypeOf(object) = @ptrCast(@alignCast(this.object));
layout.deinit();
}
}.deinit,