diff options
author | 2023-05-08 22:34:01 -0700 | |
---|---|---|
committer | 2023-05-08 22:34:01 -0700 | |
commit | 73b0d8a51cc86ba47d37f0dadf0f871fc402668c (patch) | |
tree | 20f90a208075bbcd28dde442fa526f7737cb7ba0 /src/meta.zig | |
parent | b874d0b387d27efc5f0a78c5391889ecea24db2e (diff) | |
download | bun-73b0d8a51cc86ba47d37f0dadf0f871fc402668c.tar.gz bun-73b0d8a51cc86ba47d37f0dadf0f871fc402668c.tar.zst bun-73b0d8a51cc86ba47d37f0dadf0f871fc402668c.zip |
Make the enum serializer more flexible
Diffstat (limited to '')
-rw-r--r-- | src/meta.zig | 15 |
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]; +} |