authorgravatar for benjamin.j.grant@gmail.com190n <benjamin.j.grant@gmail.com> 2025-03-04 11:12:00-08:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-03-06 08:41:51+01:00
log1e0739f0c6c7d731771ea3df140a1e5462f27a7e
tree7d43297404eca11e51aaab1be2be540aee8efbbb
parent5f7dfc357740e765fad3d8deb246b6dd9aef3fc0

std.enums.tagName: preserve sentinel in return value


1 files changed, 1 insertions(+), 1 deletions(-)

lib/std/enums.zig+1-1
...@@ -55,7 +55,7 @@ pub fn values(comptime E: type) []const E {...@@ -55,7 +55,7 @@ pub fn values(comptime E: type) []const E {
55/// A safe alternative to @tagName() for non-exhaustive enums that doesn't55/// A safe alternative to @tagName() for non-exhaustive enums that doesn't
56/// panic when `e` has no tagged value.56/// panic when `e` has no tagged value.
57/// Returns the tag name for `e` or null if no tag exists.57/// Returns the tag name for `e` or null if no tag exists.
58pub fn tagName(comptime E: type, e: E) ?[]const u8 {58pub fn tagName(comptime E: type, e: E) ?[:0]const u8 {
59 return inline for (@typeInfo(E).@"enum".fields) |f| {59 return inline for (@typeInfo(E).@"enum".fields) |f| {
60 if (@intFromEnum(e) == f.value) break f.name;60 if (@intFromEnum(e) == f.value) break f.name;
61 } else null;61 } else null;