-
Notifications
You must be signed in to change notification settings - Fork 123
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
Derive From for Enum has strange defaults or might be a regression #105
Comments
I agree that this is indeed undesirable. This happened, because I removed the code that ignored both variants when the type was the same. The reason for this was that it would be confusing if you put #[from] on two variants and if they had the same type it would silently not add those implementations (instead of giving an error). I think it makes sense to fix this case though, where nothing is explicitly enabled or disabled. For now a slightly shorter solution would be to enable the implementations for variants that you want explicitly, instead of ignoring the ones you don't. You can do this by putting a bare #[from] attribute on the top three variants in your example. |
The new behavior doesn't work well for a few of my enums too: #[derive(Clone, Debug, PartialEq, Serialize, Deserialize, derive_more::From)]
pub enum Ability {
#[from(ignore)]
Knockback,
#[from(ignore)]
Club,
Jump(Jump),
#[from(ignore)]
Poison,
#[from(ignore)]
ExplodePush,
#[from(ignore)]
ExplodeDamage,
#[from(ignore)]
ExplodeFire,
#[from(ignore)]
ExplodePoison,
Bomb(Bomb),
BombPush(BombPush),
BombFire(BombFire),
BombPoison(BombPoison),
BombDemonic(BombDemonic),
#[from(ignore)]
Summon,
#[from(ignore)]
Vanish,
#[from(ignore)]
Dash,
Rage(Rage),
Heal(Heal),
#[from(ignore)]
Bloodlust,
} upd: it looks slightly better with bare |
I pushed a fix to master, can you check if that indeed fixes the issue? |
It worked for me from what I can tell. So the C-like variants no longer seem to produce a |
Well, they still do. Just not when you have multiple C-like variants in the same enum. |
I am not sure if I would create them at all. To me this is not what I would expect them to do and besides that typing |
I think that makes sense. I think they were simply originally there for consistency. I think I'll release this hotfix tonight and rethink generating them at all by default for 1.0. |
What do you think should be doen for non C-like variants that have the same types? #[derive(From)]
enum Ints {
Int1(i32)
Int2(i32)
Uint(u32)
} Should it throw an error that Int1 and Int2 both generate the same From implementation, or should it silently generate none of them? I'm leaning towards the first. |
Error is always better than implied behaviour in such cases imo. |
Just published 0.99.1 that fixes this issue for variants without any members so, |
Thanks a lot! :) |
When using
derive_more
v0.15 I had the following on the enum with itsderive_more::From
:Now with
derive_more
v0.99 I had to use plenty#[from(ignore)]
attribute markers. To me this feels like a serious regression since those enums are kind of common. The problem is that the newderive_more::From
implementation tries to generate aFrom<()>
for each of the C-like variants.Question: Is this intended behaviour? If yes: Why? If no: Candidate for fix? :)
The text was updated successfully, but these errors were encountered: