Open FelixEngl opened 3 months ago
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.
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.
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.
Sounds good. 👍 Sadly I don't have the time to take care of that at the moment. ☹️
But if the do that we could also use https://docs.rs/phf/latest/phf/ for improved performance? 🤔
But if the do that we could also use docs.rs/phf/latest/phf for improved performance? 🤔
We'd need to bench
Hello Mickaël,
this adds various functions that I found useful while working with file-format. To sum it up:
serde
support for the enumsFileFormat
andKind
.strum
, especially theIntoEnumIterator
andAsRef<str>
are useful when writing autogenerated code.from_extension
andfrom_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 thestrum
features, we can possibly drop all of the new tests forfrom_*
except three necessary, because we can useFileFormat::iter()
to write the tests.)Best regards Felix