Skip to content

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