Interpolate unnamed enum variant fields in to_string attribute#345
Conversation
format! allows trailing spaces.
d6a88de to
b9b563c
Compare
|
Looks great! Only change is let's error on the empy |
|
I was going for an equivalency to how |
b9b563c to
71001b4
Compare
|
What about disallowing |
|
Hey, sorry for the delay here. I don't feel too strongly either way. I'm inclined to reject it for consistency with other types of enums, but could be persuaded the other way. |
Strings for unit-variants in enums were taken verbatim and not passed to
format!() since there's no associated values that *could* be formatted.
For consistency with non-unit variants these now have to use the escaped
form "{{}}", otherwise an error is produced for the format string.
|
I lean the same way, so I changed it to now invoke |
| .enumerate() | ||
| .map(|(index, field)| { | ||
| assert!(field.ident.is_none()); | ||
| let ident = syn::parse_str::<Ident>(format!("field{}", index).as_str()).unwrap(); |
There was a problem hiding this comment.
I think this use of format!() broke the no_std builds. We see error: cannot find macro format in this scope. Should this perhaps be alloc::fmt::format!?
There was a problem hiding this comment.
that format is fine as it is run at build time.
The problem is the format in the next chunk which is under a quote!
I'm thinking it would also make sense to emit an error, or at least a warning, if
{}-brackets are found in theto_string-literal on unit variants. I'd be happy to add that.