-
Notifications
You must be signed in to change notification settings - Fork 125
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
impl rename_all for #[derive(Display)] (#216) #443
base: master
Are you sure you want to change the base?
Conversation
23cd199
to
d76973d
Compare
d76973d
to
2ebbf3e
Compare
let ident = &variant.ident; | ||
|
||
if attrs.fmt.is_none() | ||
&& variant.fields.is_empty() | ||
&& attr_name != "display" | ||
&& container_attrs.rename_all.is_none() | ||
{ | ||
return Err(syn::Error::new( |
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.
@ModProg hmmm... I don't see why rename_all
argument should allow implicit naming for other traits rather than Display
only? Could you elaborate on that?
For me, the situation assert_eq!(format!("{:o}", Enum::VariantOne), "variant_one");
seems quite awkward.
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.
My idea was you could use different display traits for different ways of rename_all
if you want to.
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.
@JelteF what do you think on this? I don't particularly like this idea of abusing different fmt
traits for different naming, but maybe it's just me?
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 have seen crates use different format traits for stuff like this in the past, but I don't mind removing the functionality. i.e. make rename_all
only available for Display
.
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 agree that this is weird: assert_eq!(format!("{:o}", Enum::VariantOne), "variant_one");
But I also think assert_eq!(format!("{:o}", Enum::VariantOne), "VariantOne");
is weird. And as I understand that's what we do currently. I would be happier to see the Octal
derive simply fail for unit enum variants without an #[octal(...)]
attribute. Instead of defaulting to stringifying them in the same way as we do by default for Display
, but that would be a breaking change. And doing another major release to fix that doesn't seem worth it.
So my vote would be, let's do whatever is easiest code wise. And let's create an issue that we add to the 3.0 milestone, to remove this weird behaviour completely then.
/// Interpolation [`FmtAttribute`]. | ||
fmt: Option<FmtAttribute>, | ||
|
||
/// Addition trait bounds. | ||
bounds: BoundsAttribute, | ||
|
||
/// Rename unit enum variants following a similar behavior as [`serde`](https://serde.rs/container-attrs.html#rename_all). | ||
rename_all: Option<T>, |
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.
@ModProg instead of modifying the ContainerAttributes
with an additional slot (which is useless for the Debug
), I think it's better to leave it "as is", and:
- Move
RenameAllAttribute
intodisplay
module. - Inside
display
module do:and parse it asstruct ContainerAttributes { rename_all: RenameAllAttribute, common: super::ContainerAttributes, }
Either<RenameAllAttribute, super::ContainerAttributes>
to omit repeating parsing of thesuper::ContainerAttributes
twice.
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 thought It'd make sense to allow to have rename_all
and bounds
in the same attribute. But that will only at most save one line anyway.
Resolves #216
Checklist