diff options
Diffstat (limited to 'src/util.zig')
-rw-r--r-- | src/util.zig | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/util.zig b/src/util.zig new file mode 100644 index 0000000..b701ff6 --- /dev/null +++ b/src/util.zig @@ -0,0 +1,14 @@ +const std = @import("std"); + +// Returns an array of all the fields in the given +// type replacing all '_' with '-'. +pub fn RPCFields(comptime E: type) []const []const u8 { + @setEvalBranchQuota(10000); + var names: []const []const u8 = &[_][]const u8{}; + for (std.meta.fields(E)) |field| { + var name: [field.name.len]u8 = undefined; + _ = std.mem.replace(u8, field.name, &[_]u8{'_'}, &[_]u8{'-'}, &name); + names = names ++ &[_][]const u8{&name}; + } + return names; +} |