mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
std.enums.tagName: preserve sentinel in return value
This commit is contained in:
parent
5f7dfc3577
commit
1e0739f0c6
1 changed files with 1 additions and 1 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue