-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interpolate unnamed enum variant fields in to_string attribute #345
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.