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

Use enum named fields in to_string macro #294

Merged
merged 5 commits into from
Jan 21, 2024

Conversation

Arian8j2
Copy link
Contributor

@Arian8j2 Arian8j2 commented Sep 6, 2023

Not much, Just see the example:

#[derive(strum_macros::Display)]
enum Color {
    #[strum(to_string = "saturation is {sat}")]
    Purple { sat: usize },
}

assert_eq!(
    String::from("saturation is 10"),
    (Color::Purple { sat: 10 }).to_string().as_ref()
);

@Arian8j2
Copy link
Contributor Author

Arian8j2 commented Sep 6, 2023

Seems like environments in CI that failed uses old version of rustc and doesn't support format like these:

let name = "alex";
format!("my name is {name}")

and formats like these are used internally to implement this pr, but i think explicitly assigning each variable like these:

let name = "alex";
format!("my name is {name}", name = name)

will make this possible in older rustc versions, I will try to implement this tomorrow.

@Arian8j2 Arian8j2 changed the title Use named variables in to_string macro Use enum named fields in to_string macro Sep 7, 2023
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

Successfully merging this pull request may close these issues.

2 participants