strum icon indicating copy to clipboard operation
strum copied to clipboard

Use enum named fields in to_string macro

Open Arian8j2 opened this issue 1 year ago • 1 comments

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 avatar Sep 06 '23 16:09 Arian8j2

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 avatar Sep 06 '23 21:09 Arian8j2