From 17f3a7b655938eb47efc2bbe884e68786bce6077 Mon Sep 17 00:00:00 2001 From: Christian Segundo Date: Mon, 12 Jun 2023 01:37:45 +0200 Subject: add torrent get raw --- src/util.zig | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/util.zig') 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; +} -- cgit v1.2.3