Replies: 1 comment
-
|
I'd also like to point out that the snake case rules are inconsistent between use strum::*;
#[derive(EnumIs, EnumTryAs, Display, AsRefStr, IntoStaticStr, EnumString, VariantNames)]
#[strum(serialize_all = "snake_case")]
enum E {
// methods use `i_32`
// string reprs are `"i32"`
I32(i32),
// methods use `c_str`
// string reprs are `"c_str"`
CStr(String),
}
// VARIANTS = &["i32", "c_str"]Again, these two concepts are semantically different, but it's still strange to have methods and str reprs with different naming conventions when using defaults for both. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Request
Currently,
EnumIsandEnumTryAsgenerate methods with a simple snake case transformation from variant names.It would be nice to customize generated method names, since some snake case rules could look awkward, both from
heckand the customizedsnakify:Initially I thought of suggesting overriding names using
serializeattribute since it would be easier to implement but not only it would break existing code, it is also semantically incorrect (display representation used as method name).So I guess the only option is to add yet another macro attribute specifically for this use case.
Naming issues
On the topic of being semantically correct, I got a bone to pick with
EnumTryAsspecifically, because it doesn't follow naming conventions.The generated name prefix for the method that takes
self(move) doesn't follow clippy's naming convention.try_as_*implies taking&selfas the receiver. For moves, it should betry_into_*.If
try_into_*(self) -> Option<T>is generated, thentry_as_*_ref(&self) -> Option<&T>could drop the_refsuffix totry_as_*(&self) -> Option<&T>.Another point, but this one is bikeshedable since it's not a convention, is that
tryis usually used for fallible operations. None of the generated methods are fallible, so IMO it feels weird to usetry_as_variant_refand match against anOption, or when using the?operator ontry_*methods.Edit:
For the
try"issue", I forgot to add my suggestion to simply drop thetry_prefix.into_<variant>(self) -> Option<T>as_variant(&self) -> Option<&T>as_variant_mut(&mut self) -> Option<&mut T>Obviously these changes break compatibility. I don't know if adding an entirely new derive with a new name (like
EnumAs) that does the same thing would be acceptable, but it wouldn't break compatibility.Beta Was this translation helpful? Give feedback.
All reactions