strum
strum copied to clipboard
Use proper SCREAMING_SNAKE_CASE conversion for EnumCount
If an enum is called FooBarBaz
, EnumCount
will name the constant FOOBARBAZ_COUNT
. I believe FOO_BAR_BAZ_COUNT
would be more expected. This can be achieved by heck
, which is already a dependency of strum
.
Thanks for bringing this up! I have a few thoughts on the issue.
- This would be a breaking change, which in my mind means there's a higher threshold to reach than simply adding a new feature.
- I definitely agree that
FOO_BAR_BAZ_COUNT
is cleaner in your example. I'm not sure that is true in all cases though. If the enum was calledMy_eNum1a2B
, it wouldn't be obvious to me what the snake_case version is, but I can easily figure out the uppercase version.
I'm going to tag this as "feedback wanted" because I think more opinions on the matter would be useful.
You can also create a new constant and export that name while still getting most of the benefits of using strum
pub const FOO_BAR_BAZ_COUNT: usize = FOOBARBAZ_COUNT;
- This would be a breaking change, which in my mind means there's a higher threshold to reach than simply adding a new feature.
I am aware that this would be a breaking change. However, strum could
generate both styles of constants, and mark the "simple uppercase" ones
as deprecated and doc(hidden)
, to facilitate a transition period.
- I definitely agree that
FOO_BAR_BAZ_COUNT
is cleaner in your example. I'm not sure that is true in all cases though. If the enum was calledMy_eNum1a2B
, it wouldn't be obvious to me what the snake_case version is, but I can easily figure out the uppercase version.
If that's what you name your enums, you did this to yourself. If it's
just the fact that you're using a non-standard naming convention, heck
handles this well - in fact, you don't even need to know the original
"case".
I would also like to see this change implemented. Currently enums with a few words in their names get hard to read generated constants for their count. Users are already expecting breaking changes because of semver rules about libraries below version 1.0.