Skip to content

Deprecate std.enums.nameCast. #23524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 15, 2025
Merged

Deprecate std.enums.nameCast. #23524

merged 2 commits into from
Apr 15, 2025

Conversation

AndrewKraevskii
Copy link
Contributor

Recently there is a tendency to remove stuff from std.meta. And std.enums.nameCast seems like a missed function since it's in a different namespace.

More specific reasons:
@field(Enum, @tagName(tag))
^ is just shorter to write compared to
std.meta.nameCast(Enum, tag)

nameCast's only advantage is that it can be used interchangeably with strings. But a search through common codebases (zig, bun, tigerbeetle, ...) only tigerbeetle uses it 3 times and only in non-generic way e.g. exclusively with strings or with tags.

It's also pretty buggy and allows usage with bizarre parameters such as std.meta.nameCast(type, Enum).

Recently there is a tendency to remove stuff from std.meta.
And std.enums.nameCast seems like a missed function since
it's in a different namespace.

Reasons:
`@field(Enum, @TagName(tag))`
^ is just shorter to write compared to
`std.meta.nameCast(Enum, tag)`

nameCast's only advantage is that it can be used interchangeably with strings.
But a search through common codebases (zig, bun, tigerbeetle, ...) only
tigerbeetle uses it and only in non-generic way e.g. exclusively with strings or with tags.

It's also pretty buggy and allows usage with bizarre parameters such as
`std.meta.nameCast(type, Enum)`.
Co-authored-by: Alex Rønne Petersen <[email protected]>
@alexrp alexrp merged commit 530228d into ziglang:master Apr 15, 2025
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants