aboutsummaryrefslogtreecommitdiff
path: root/src/meta.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-05-08 22:34:01 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-05-08 22:34:01 -0700
commit73b0d8a51cc86ba47d37f0dadf0f871fc402668c (patch)
tree20f90a208075bbcd28dde442fa526f7737cb7ba0 /src/meta.zig
parentb874d0b387d27efc5f0a78c5391889ecea24db2e (diff)
downloadbun-73b0d8a51cc86ba47d37f0dadf0f871fc402668c.tar.gz
bun-73b0d8a51cc86ba47d37f0dadf0f871fc402668c.tar.zst
bun-73b0d8a51cc86ba47d37f0dadf0f871fc402668c.zip
Make the enum serializer more flexible
Diffstat (limited to '')
-rw-r--r--src/meta.zig15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/meta.zig b/src/meta.zig
index 5bf99bbaa..954e77f29 100644
--- a/src/meta.zig
+++ b/src/meta.zig
@@ -24,3 +24,18 @@ pub fn typeBaseName(comptime fullname: []const u8) []const u8 {
const name = if (idx == null) fullname else fullname[(idx.? + 1)..];
return comptime std.fmt.comptimePrint("{s}", .{name});
}
+
+pub fn enumFieldNames(comptime Type: type) []const []const u8 {
+ var names: [std.meta.fields(Type).len][]const u8 = std.meta.fieldNames(Type).*;
+ var i: usize = 0;
+ for (names) |name| {
+ // zig seems to include "_" or an empty string in the list of enum field names
+ // it makes sense, but humans don't want that
+ if (@import("root").bun.strings.eqlAnyComptime(name, &.{ "_none", "", "_" })) {
+ continue;
+ }
+ names[i] = name;
+ i += 1;
+ }
+ return names[0..i];
+}