summaryrefslogtreecommitdiff
path: root/helpers.zig
diff options
context:
space:
mode:
authorGravatar Vincent Rischmann2023-11-23 21:43:30 +0100
committerGravatar Vincent Rischmann2023-11-23 21:43:30 +0100
commit123eb09609c09f1187a1d29bd5dbed9e0962ec54 (patch)
tree191c0ac15659665390a6e958a98208dc8d08053a /helpers.zig
parentMerge pull request #143 from edyu/master (diff)
parentuse @hasField (diff)
downloadzig-sqlite-123eb09609c09f1187a1d29bd5dbed9e0962ec54.tar.gz
zig-sqlite-123eb09609c09f1187a1d29bd5dbed9e0962ec54.tar.xz
zig-sqlite-123eb09609c09f1187a1d29bd5dbed9e0962ec54.zip
Merge branch 'fix-latest-zig'
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}