-
Notifications
You must be signed in to change notification settings - Fork 139
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
how to round trip Display and EnumString with default="true" #86
Comments
This is a breaking change, but it seems internally consistent so I'd be open to fixing/changing it. Is this something you're opening to doing? |
not sure... it came up for me during a refactor of a crate where this was being used... but i'm not sure if i'll be using this crate moving forward on that project as we might not even be using the enum it was relevant to any more |
This attribute causes the to_string to use the value of a tuple-like variant to be used as the to_string value. E.g. Color::Green("lime").to_string() will equal "lime" not "Green" Fixes: how to round trip Display and EnumString with default="true" Peternator7#86
This attribute causes the to_string to use the value of a tuple-like variant to be used as the to_string value. E.g. Color::Green("lime").to_string() will equal "lime" not "Green" Fixes: how to round trip Display and EnumString with default="true" Peternator7#86
The default attribute on a tuple like variant now causes the to_string and display format to use the value of the tuple rather than the name of the variant. E.g. Color::Green("lime").to_string() will equal "lime" not "Green" Fixes: how to round trip Display and EnumString with default="true" Peternator7#86 BREAKING CHANGE This changes how Display and ToString cause the following to renders: ```rust #[strum(default)] Green(String) ``` To maintain the previous behavior (use the variant name): ```rust #[strum(default, to_string("Green"))] Green(String) ```
The default attribute on a tuple like variant now causes the to_string and display format to use the value of the tuple rather than the name of the variant. E.g. Color::Green("lime").to_string() will equal "lime" not "Green" Fixes: how to round trip Display and EnumString with default="true" #86 BREAKING CHANGE This changes how Display and ToString cause the following to renders: ```rust #[strum(default)] Green(String) ``` To maintain the previous behavior (use the variant name): ```rust #[strum(default, to_string("Green"))] Green(String) ```
IWBNI this could be extended to AsRefStr. As it currently stands, |
This is implemented in the linked PR #270 @fullermd, can you open a new issue for that request. The issue is that for |
I have some default variant that contains a string, like:
but if i do:
i get
"Bar"
not"baz"
so then there's no way to round trip it back into the originalFooEnum
The text was updated successfully, but these errors were encountered: