Skip to content
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

Converge my crate into yours #324

Open
wiiznokes opened this issue Dec 18, 2023 · 2 comments
Open

Converge my crate into yours #324

wiiznokes opened this issue Dec 18, 2023 · 2 comments

Comments

@wiiznokes
Copy link

Hi, this is my crate: https://crates.io/crates/light_enum.

Are you interested in a pull request that adds its 2 Derive keywords (LightEnum and Values) ?
Values could be renamed into Array.

I wrote it without thinking that there were already crate for it. Doing this with the derive_more helper functions will be easier I think. And I know there is also EnumDiscriminants from strum.

What do you think?

@JelteF
Copy link
Owner

JelteF commented Dec 18, 2023

I'm not opposed to adding more derives to this crate. But they should have a utility that's not already provided by the other derives or by normal Rust constructs (or at least provide that utility in a easier to use way).

The examples in your crate its README seem already covered:

  • The LightEnum example could trivially be rewritten using the IsVariant derive that's already part of derive_more
  • The Values derive example is so abstract that I don't really understand what it's practical usage is in actual code. i.e. what do you do with an array containing all variants of an enum?

To be clear it's not to say that these are not useful derives, just that based on the README I don't understand what it is.

@wiiznokes
Copy link
Author

The LightEnum example could trivially be rewritten using the IsVariant derive that's already part of derive_more

I'm not so sure about that. light_enum provide a way to have a representation of an enum variant.
An usecase for it could be a fonction that generate a enum variant given his Light representation.

The Values derive example is so abstract that I don't really understand what it's practical usage is in actual code. i.e. what do you do with an array containing all variants of an enum?

This is basically the same as EnumIter, but, from my little understanding of Rust, more optimize if you know you will use it in your program, and if your enum will not be very huge (and also if you know you will iter over ALL posible variant of your enum).
But my implementation is not perfect, because it don't use Default::default() like EnumIter (but it could be).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants