strum
strum copied to clipboard
Use enum named fields in to_string macro
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()
);
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.