diff options
| author | 2023-11-23 21:35:16 +0100 | |
|---|---|---|
| committer | 2023-11-23 21:36:06 +0100 | |
| commit | 7d4d8fa55b98269666a8fc1f73795a78c10bd073 (patch) | |
| tree | 2c6570d8e0daefa52ac4e2e86f7ee95b8058b7a4 /helpers.zig | |
| parent | add the isZigString helper (diff) | |
| download | zig-sqlite-7d4d8fa55b98269666a8fc1f73795a78c10bd073.tar.gz zig-sqlite-7d4d8fa55b98269666a8fc1f73795a78c10bd073.tar.xz zig-sqlite-7d4d8fa55b98269666a8fc1f73795a78c10bd073.zip | |
add the fasFn helper
Diffstat (limited to '')
| -rw-r--r-- | helpers.zig | 16 |
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`. | ||
| 91 | pub 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 | } | ||