summaryrefslogtreecommitdiff
path: root/src/util.zig
blob: b701ff6e44ab71c94d819ee947aa56a6991a8f6b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
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;
}