Skip to content
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

prefix attribute does not work for EnumString #394

Open
yrns opened this issue Dec 12, 2024 · 1 comment
Open

prefix attribute does not work for EnumString #394

yrns opened this issue Dec 12, 2024 · 1 comment

Comments

@yrns
Copy link

yrns commented Dec 12, 2024

Maybe this isn't supposed to work, but the changelist kind of implies it should:

use strum_macros::{Display, EnumString};

#[derive(Debug, PartialEq, EnumString, Display)]
#[strum(prefix = "colour/")]
enum Color {
    #[strum(to_string = "RedRed")]
    Red,
}

fn main() {
    assert_eq!(String::from("colour/RedRed"), (Color::Red).to_string()); // works
    assert_eq!(Color::try_from("colour/Red"), Ok(Color::Red)); // this fails
    assert_eq!(Color::try_from("colour/RedRed"), Ok(Color::Red)); // this fails
}
@Peternator7
Copy link
Owner

Flipping through the code, this is definitely not implemented for TryFrom/FromStr 😟. Must've been an oversight back then. I think fixing it for consistency is reasonable, but it is a breaking change so I'll probably be strategic about when it merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants