Skip to content

Commit

Permalink
Export meta module. (#23)
Browse files Browse the repository at this point in the history
I found the helpers in `meta` to be useful in downstream code. For now
I'm exporting it under `pgzx.meta`. I wonder if we eventually want to
introduce a `pgzx.lib` namespace for common utility functions that are
not directly related to Postgres code.
  • Loading branch information
urso committed Mar 18, 2024
1 parent 51d84a6 commit 329dbba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/pgzx.zig
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,8 @@ pub const utils = @import("pgzx/utils.zig");
pub const intr = @import("pgzx/interrupts.zig");
pub const testing = @import("pgzx/testing.zig");

// reexport the meta module. Although quite generic, it is useful to have these
// helpers around at times.
pub const meta = @import("pgzx/meta.zig");

pub const guc = utils.guc;
7 changes: 7 additions & 0 deletions src/pgzx/meta.zig
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,10 @@ pub inline fn isPrimitive(comptime T: type) bool {
else => false,
};
}

pub inline fn fnReturnType(comptime T: type, comptime fnName: []const u8) type {
return switch (@typeInfo(@field(T, fnName))) {
.Fn => |f| f.return_type.?,
else => @compileError("Expected a function type"),
};
}

0 comments on commit 329dbba

Please sign in to comment.