-
Notifications
You must be signed in to change notification settings - Fork 120
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
Implement FromStr for Enum #59
Comments
That's a reasonable use case indeed. Feel free to send a PR that adds it.
…On Fri, 9 Nov 2018, 08:23 Sven-Hendrik Haase ***@***.*** wrote:
I have an enum with a long list like this:
enum ThingType {
A,
B,
...
Z,
}
I want to be able to do
ThingType::from_str("A")
and get ThingType::A.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#59>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABG8JhY2XEar6FQoiGulZ2qz1fb5iDFdks5utS1XgaJpZM4YWFTC>
.
|
It would be nice to also have the option to rename all to lowercase, camelcase and more, like serde. |
You might be interested in use std::str::FromStr;
use strum::{Display, EnumString};
#[derive(Display, EnumString)]
#[strum(serialize_all = "SCREAMING-KEBAB-CASE")]
enum MediaType {
Audio,
Video,
Subtitles,
ClosedCaptions,
}
fn main() {
assert_eq!(format!(MediaType::ClosedCaptions), "CLOSED-CAPTIONS".to_string());
assert_eq!(MediaType::from_str("CLOSED-CAPTIONS"), MediaType::ClosedCaptions);
} |
aj-bagwell
added a commit
to aj-bagwell/derive_more
that referenced
this issue
Dec 3, 2021
This allows deriving FromStr for enums with no fields in the obvious way fixes JelteF#59
aj-bagwell
added a commit
to aj-bagwell/derive_more
that referenced
this issue
Dec 3, 2021
This allows deriving FromStr for enums with no fields in the obvious way fixes JelteF#59
aj-bagwell
added a commit
to aj-bagwell/derive_more
that referenced
this issue
Dec 3, 2021
This allows deriving FromStr for enums with no fields in the obvious way fixes JelteF#59
aj-bagwell
added a commit
to aj-bagwell/derive_more
that referenced
this issue
Dec 3, 2021
This allows deriving FromStr for enums with no fields in the obvious way fixes JelteF#59
aj-bagwell
added a commit
to aj-bagwell/derive_more
that referenced
this issue
Dec 3, 2021
This allows deriving FromStr for enums with no fields in the obvious way fixes JelteF#59
aj-bagwell
added a commit
to aj-bagwell/derive_more
that referenced
this issue
Dec 3, 2021
This allows deriving FromStr for enums with no fields in the obvious way fixes JelteF#59
aj-bagwell
added a commit
to aj-bagwell/derive_more
that referenced
this issue
Dec 3, 2021
This allows deriving FromStr for enums with no fields in the obvious way fixes JelteF#59
aj-bagwell
added a commit
to aj-bagwell/derive_more
that referenced
this issue
Feb 8, 2022
This allows deriving FromStr for enums with no fields in the obvious way fixes JelteF#59
JelteF
pushed a commit
that referenced
this issue
Feb 8, 2022
This allows deriving FromStr for enums with no fields in the obvious way fixes #59
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have an enum with a long list like this:
I want to be able to do
and get
ThingType::A
.The text was updated successfully, but these errors were encountered: