summaryrefslogtreecommitdiff
path: root/src/util.zig
diff options
context:
space:
mode:
authorChristian Segundo2023-06-12 01:37:45 +0200
committerChristian Segundo2023-06-12 01:37:45 +0200
commit17f3a7b655938eb47efc2bbe884e68786bce6077 (patch)
treec180bca82e03ebd8aa4beb9c9b1fbf4c21a6c264 /src/util.zig
parent6eaf6a8f3f3880372bdfa0027805213d109a80cc (diff)
downloadzmission-17f3a7b655938eb47efc2bbe884e68786bce6077.tar.gz
add torrent get raw
Diffstat (limited to 'src/util.zig')
-rw-r--r--src/util.zig15
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;
+}