Is below possible or serde just does not allow any kind expressions in the alias?
#[test]
fn test_stringify_in_macro(){
macro_rules! create_enum {
($NAME:ident, $($VARIANT:tt : $VALUE:literal),*) => {
#[derive(Debug, serde::Serialize)]
pub enum $NAME {
$(
#[serde(rename = $VALUE)]
#[serde(alias = "stringify!($VARIANT)")] // how to stringify the variant for serde? is it possible?
$VARIANT
),*
}
};
}
create_enum!(MyEnum, One: "1", Two: "2", Three: "3");
let x = MyEnum::One;
println!("{:?}", x);
}