mmalecot / file-format

Crate for determining the file format of a given file or stream
Apache License 2.0
94 stars 15 forks source link

Add Serde, Strum and From features #63

Open FelixEngl opened 3 months ago

FelixEngl commented 3 months ago

Hello Mickaël,

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

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 commented 2 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.

MOZGIII commented 1 month ago

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.

FelixEngl commented 4 weeks ago

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? 🤔

MOZGIII commented 4 weeks ago

But if the do that we could also use docs.rs/phf/latest/phf for improved performance? 🤔

We'd need to bench