From 43c411dcd76fc7b36345723d9fd84041de90225f Mon Sep 17 00:00:00 2001 From: renerocksai Date: Sun, 30 Mar 2025 15:03:35 +0200 Subject: [PATCH] fix router.zig type checking, remove wrk examples from build.zig --- build.zig | 2 -- src/router.zig | 18 ++++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/build.zig b/build.zig index b13002a..e020e26 100644 --- a/build.zig +++ b/build.zig @@ -60,8 +60,6 @@ pub fn build(b: *std.Build) !void { .{ .name = "serve", .src = "examples/serve/serve.zig" }, .{ .name = "hello_json", .src = "examples/hello_json/hello_json.zig" }, .{ .name = "endpoint", .src = "examples/endpoint/main.zig" }, - .{ .name = "wrk", .src = "wrk/zig/main.zig" }, - .{ .name = "wrk_zigstd", .src = "wrk/zigstd/main.zig" }, .{ .name = "mustache", .src = "examples/mustache/mustache.zig" }, .{ .name = "endpoint_auth", .src = "examples/endpoint_auth/endpoint_auth.zig" }, .{ .name = "http_params", .src = "examples/http_params/http_params.zig" }, diff --git a/src/router.zig b/src/router.zig index e6bfe23..ff35831 100644 --- a/src/router.zig +++ b/src/router.zig @@ -82,10 +82,10 @@ pub fn handle_func(self: *Router, path: []const u8, instance: *anyopaque, handle // Need to check: // 1) handler is function pointer const f = blk: { - if (hand_info == .Pointer) { - const inner = @typeInfo(hand_info.Pointer.child); - if (inner == .Fn) { - break :blk inner.Fn; + if (hand_info == .pointer) { + const inner = @typeInfo(hand_info.pointer.child); + if (inner == .@"fn") { + break :blk inner.@"fn"; } } @compileError("Expected handler to be a function pointer. Found " ++ @@ -104,8 +104,14 @@ pub fn handle_func(self: *Router, path: []const u8, instance: *anyopaque, handle // 3) handler returns void const ret_info = @typeInfo(f.return_type.?); - if (ret_info != .Void) { - @compileError("Expected handler's return type to be void. Found " ++ + if (ret_info != .error_union) { + @compileError("Expected handler's return type to be !void. Found " ++ + @typeName(f.return_type.?)); + } + + const payload = @typeInfo(ret_info.error_union.payload); + if (payload != .void) { + @compileError("Expected handler's return type to be !void. Found " ++ @typeName(f.return_type.?)); } }