commit 1e0739f0c6c7d731771ea3df140a1e5462f27a7e (tree)
parent 5f7dfc357740e765fad3d8deb246b6dd9aef3fc0
Author: 190n <benjamin.j.grant@gmail.com>
Date: Tue, 4 Mar 2025 11:12:00 -0800
std.enums.tagName: preserve sentinel in return value
Diffstat:
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/std/enums.zig b/lib/std/enums.zig
@@ -55,7 +55,7 @@ pub fn values(comptime E: type) []const E {
/// A safe alternative to @tagName() for non-exhaustive enums that doesn't
/// panic when `e` has no tagged value.
/// Returns the tag name for `e` or null if no tag exists.
-pub fn tagName(comptime E: type, e: E) ?[]const u8 {
+pub fn tagName(comptime E: type, e: E) ?[:0]const u8 {
return inline for (@typeInfo(E).@"enum".fields) |f| {
if (@intFromEnum(e) == f.value) break f.name;
} else null;