-
Notifications
You must be signed in to change notification settings - Fork 152
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
Add #[strum(transparent)]
argument
#258
Comments
This would be good to have, without which I have no choice but to write out the instances by hand: pub enum System {
Aarch64Linux,
X86_64Linux,
X86_64Darwin,
Aarch64Darwin,
Other(String),
}
impl From<&str> for System {
fn from(s: &str) -> Self {
match s {
"aarch64-linux" => Self::Aarch64Linux,
"x86_64-linux" => Self::X86_64Linux,
"x86_64-darwin" => Self::X86_64Darwin,
"aarch64-darwin" => Self::Aarch64Darwin,
_ => Self::Other(s.to_string()),
}
}
}
impl From<System> for String {
fn from(s: System) -> Self {
match s {
System::Aarch64Linux => "aarch64-linux".to_string(),
System::X86_64Linux => "x86_64-linux".to_string(),
System::X86_64Darwin => "x86_64-darwin".to_string(),
System::Aarch64Darwin => "aarch64-darwin".to_string(),
System::Other(s) => s,
}
}
} |
Was hoping to get some feedback from a maintainer, but I really think this would be a useful feature so I might have a shot at it after the holidays. Thanks for the encouragement @srid ! |
#[strum(transparent)]
argument
@bobozaur seems to not be documented, but from checking the code using |
@divagant-martian While similar in some cases, this is not the same thing. The |
This crate is amazing for tackling a lot of boilerplate code and also ensuring variant name changes propagate to the trait implementations. I use
AsRefStr
andEnumString
quite a lot.However, a lot of times I've found myself in the situation of having something like this:
Afaik there's no way of propagating the
AsRef<str>
orFromStr
implementations to the underlyingString
. What do you think about implementing atransparent
argument to the attribute, similar to#[serde(transparent)]
- only for one field provided in an unnamed/named fashion.So then we could do:
I could try and pick this up if you like the idea. I think it would be handy for a lot of people.
The text was updated successfully, but these errors were encountered: