It would look more like this:
const A = struct { B };
const C = struct { b: B };
const B = struct {
ptr: *anyopaque,
d: *const D,
pub fn do(self: B, args: A) void {
return self.d.func(self.ptr, args);
}
};
const D = struct {
func: *const fn (ctx: *anyopaque, args: A) void,
};
fn funky(ctx: *anyopaque, args: A) void {
_ = .{ ctx, args };
}
test "deploop" {
const a: A = .{ .b = undefined };
const c: C = .{ .b = .{ .ptr = @ptrCast(@alignCast(@constCast(&A))), .d = &.{ .func = &funky } } };
_ = .{ a, c };
try std.testing.expect(true);
}
const std = @import("std");
Try it and see what you think.