summaryrefslogtreecommitdiff
path: root/helpers.zig
diff options
context:
space:
mode:
authorGravatar Vincent Rischmann2023-11-23 21:35:16 +0100
committerGravatar Vincent Rischmann2023-11-23 21:36:06 +0100
commit7d4d8fa55b98269666a8fc1f73795a78c10bd073 (patch)
tree2c6570d8e0daefa52ac4e2e86f7ee95b8058b7a4 /helpers.zig
parentadd the isZigString helper (diff)
downloadzig-sqlite-7d4d8fa55b98269666a8fc1f73795a78c10bd073.tar.gz
zig-sqlite-7d4d8fa55b98269666a8fc1f73795a78c10bd073.tar.xz
zig-sqlite-7d4d8fa55b98269666a8fc1f73795a78c10bd073.zip
add the fasFn helper
Diffstat (limited to '')
-rw-r--r--helpers.zig16
1 files changed, 16 insertions, 0 deletions
diff --git a/helpers.zig b/helpers.zig
index 1a56231..7bb695e 100644
--- a/helpers.zig
+++ b/helpers.zig
@@ -86,3 +86,19 @@ fn sliceFromValue(sqlite_value: *c.sqlite3_value) []const u8 {
86 86
87 return value[0..size]; 87 return value[0..size];
88} 88}
89
90// Returns true if the type T has a function named `name`.
91pub fn hasFn(comptime T: type, comptime name: []const u8) bool {
92 if (!@hasDecl(T, name)) {
93 return false;
94 }
95
96 const decl = @field(T, name);
97 const decl_type = @TypeOf(decl);
98 const decl_type_info = @typeInfo(decl_type);
99
100 return switch (decl_type_info) {
101 .Fn => true,
102 else => false,
103 };
104}