const std = @import("std"); const Response = @import("../Response.zig"); const Route = @import("../Route.zig"); route: Route, base: *const anyopaque, handler: *const fn ( *const anyopaque, std.mem.Allocator, std.mem.Allocator, std.Io, *std.http.Server.Request, ) Response, pub fn from(instance: anytype, route: Route) @This() { const PtrT = @TypeOf(instance); const func = struct { pub fn handle( base: *const anyopaque, gpa: std.mem.Allocator, arena: std.mem.Allocator, io: std.Io, request: *std.http.Server.Request, ) Response { return @as(PtrT, @ptrCast(@alignCast(base))).handle(gpa, arena, io, request); } }.handle; return .{ .base = @ptrCast(instance), .handler = func, .route = route, }; } pub fn handle( self: *const @This(), gpa: std.mem.Allocator, arena: std.mem.Allocator, io: std.Io, request: *std.http.Server.Request, ) Response { return self.handler(self.base, gpa, arena, io, request); }