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

Add Serde, Strum and From features #63

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

FelixEngl
Copy link

Hello Mickaël,

this adds various functions that I found useful while working with file-format.
To sum it up:

  • Adds optional non-std serde support for the enums FileFormat and Kind.
  • Adds optional extensions from strum, especially the IntoEnumIterator and AsRef<str> are useful when writing autogenerated code.
  • Adds the optional features from_extension and from_media_type. Both are returning a slice with the possible associated file formats for a media type or an extension. I also included the tests for all existing file formats as well as some health checks to ensure that all newly added file formats are also valid.

I know it looks like a big pull request, but this is mostly caused by adding all the necessary tests and calling the macros for generating the from_* methods. The real code changes are only around 80 to 90 lines. (To be honest, if we accept the strum features, we can possibly drop all of the new tests for from_* except three necessary, because we can use FileFormat::iter() to write the tests.)

Best regards
Felix

@mmalecot
Copy link
Owner

Hello Felix,

Thank you very much for your PR.
I'm currently on holiday, but I'll have a look at it when I get back.

@MOZGIII
Copy link

MOZGIII commented Oct 16, 2024

I have checked out the proposed implementation, and the approach of manually authoring the mapping seems suboptimal. It is very easy to make a mistake and for the mappings to go out of sync with the actual formats. I propose adding a build script instead that would generate the source code files on the fly by collecting indexes from the all-formats enumerator provided by strum.

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.

3 participants