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 optional binrw/BinRead implementation #370

Closed
wants to merge 1 commit into from

Conversation

caitp
Copy link

@caitp caitp commented Jun 28, 2023

The goal here is ultimately to teach serde to deserialize raw bitfields from a binary file format, being mindful of the expected endian-ness of the structs. This doesn't get it there from the start, afaik -- but it does seem like a usable starting point.

I don't write a ton of Rust code, so I won't be surprised if this isn't the best way to get this done. Please let me know if there's a better way to do this.

@KodrAus
Copy link
Member

KodrAus commented Jun 28, 2023

Hi @caitp 👋

Thanks for working on this!

Since binrw is unstable, we unfortunately can't add direct support for it in bitflags, but you can still define bitflags types that you can apply its attributes to. We have an example using the zerocopy library here. I think the principle should be the same for binrw.

@DCNick3
Copy link

DCNick3 commented Jul 12, 2023

This is an unfortunate degradation of ergonomics compared to 1.x release, where the derive(BinRead) worked without the impl mode

@KodrAus
Copy link
Member

KodrAus commented Jul 14, 2023

@DCNick3 Yes it is a difference with 1.x, but trade-offs have to be made. The 1.x behavior of simply forwarding to the underlying integer type is only useful for cases like this where you're treating them as transparent.

@DCNick3
Copy link

DCNick3 commented Jul 14, 2023

Is it possible to have the textual Debug and Display implementations when using the impl mode?

@KodrAus
Copy link
Member

KodrAus commented Jul 14, 2023

You can yes, you just have to implement traits for formatting and parsing based on the functions in the bitflags::parser module. We've got an example that shows it.

@KodrAus
Copy link
Member

KodrAus commented Mar 20, 2024

It's been a while here so I'll go ahead and close this one to keep our PR list current. I'd be happy to take this with unstable support based on the approach we have for zerocopy in the future though.

Thanks again for the PR!

@KodrAus KodrAus closed this Mar 20, 2024
@DCNick3
Copy link

DCNick3 commented Mar 20, 2024

Until the Debug impl can be derived without boilerplate (tracked in #395), I'll have to stick to bitflags 1.x.

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.

None yet

3 participants