diff options
Diffstat (limited to 'src/util.zig')
-rw-r--r-- | src/util.zig | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/util.zig b/src/util.zig index b701ff6..41c3584 100644 --- a/src/util.zig +++ b/src/util.zig @@ -1,8 +1,7 @@ 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 { +/// Returns an slice of all the fields in the given type replacing all '_' with '-'. +pub fn enumFieldsToStringSlice(comptime E: type) []const []const u8 { @setEvalBranchQuota(10000); var names: []const []const u8 = &[_][]const u8{}; for (std.meta.fields(E)) |field| { @@ -12,3 +11,13 @@ pub fn RPCFields(comptime E: type) []const []const u8 { } return names; } + +pub fn enumFieldsToSlice(comptime T: type) []const T { + var fields: []const T = &[_]T{}; + inline for (@typeInfo(T).Enum.fields) |enumField| { + fields = fields ++ &[_]T{ + @field(T, enumField.name), + }; + } + return fields; +} |