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

minimal extraction of enum_metadata from PR #207. #208

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

ratmice
Copy link
Contributor

@ratmice ratmice commented Jan 24, 2022

This is the minimal extraction of EnumMetadata, which excises OpaqueRepr from my pr #207.

It doesn't yet fix the duplicate code issue, I also think there is a function in #183 which this hadn't implemented.

I need to work on the other crate where the stuff which was excised goes however,
So If anyone wants to pick this up, by all means.

I assume what needs to be done is pull as much as we can out into strum_macros/helpers/ and then call those from the various ..._inner(..) calls. Instead of just duplicating everything. But note that the types and constness between the inherent and trait impl may differ making it difficult to remove all duplication.

Otherwise i'll try and get back to this when I can -- or we can close it and reopen at that time!

@ratmice
Copy link
Contributor Author

ratmice commented Jan 24, 2022

It seems like github's diff comparison doesn't pick up on the fact that macros/enum_metadata.rs is a copy of enum_fromrepr.rs with 70% similarity, but viewing in another diff tool like gitk should be helpful when getting rid of duplicated code.

@ratmice
Copy link
Contributor Author

ratmice commented Jan 26, 2022

So, I took a first pass at this, somehow my attempt to move out the duplicated code ended up longer than the combined duplication.
It might not be very pretty, likely requires another pass

Edit:
fwiw, I didn't think I would be able to use this macro with the stuff removed from the other branch,
because I thought once we had a type Repr: + Traits, we wouldn't be able to add additional trait bounds to it.

Turns out that was wrong, and I can use this macro as-is in my crate,
it is here: https://github.com/ratmice/enum_extra

This uses MetadataImpl in enum_count and enum_variant_names,
in addition to enum_metadata, and from_repr from the previous commits.
@ratmice
Copy link
Contributor Author

ratmice commented Jan 28, 2022

Wonder if we should include a const REPR_TYPE_STR: &'static str = "u8" for example.

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

Successfully merging this pull request may close these issues.

1 participant