Here is the specific code in the macro that handles the default_field attribute:
Here I thought that Ok(Meta::List would handle the literal array, but apparently I misunderstood the meaning of Meta::List, because the macros still gives the error:
attribute value must be a literal
Is it impossible to pass other literals to the macro attribute besides those described in enum Lit?
This is less common. Yeah, that syntax seems good, but FYI even in Variant attributes · Serde , a string literal is preferred. #[serde(bound = "T: MyTrait")] instead of #[serde(bound = T: MyTrait)], #[serde(deserialize_with = "path::to_path")] instead of #[serde(deserialize_with = path::to_path)].
Then if you really want the syntax, it'd be a bit harder to do: manually collect tokens after the equal sign, but what if you write multple metadata in one attribute, like #[default_field = [0.1; 2], other = xxx].
If you only allow string literal, there is an inherent range for parsing: for #[default_field = "[0.1; 2]"]
a lot easier for more complicated case like #[default_field = "[0.1; 2]", other = xxx] (well, you would say this case is never allowed, then another story. Just to inform you of it.)
Sure, I can parse a string literal and use prarse(). But I would also have to deal with the array being of the right type (too much work).
That's why I wanted to know if it's possible to work with an array literal. And thanks for that