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
Constants deserialization #147
Comments
This would be really nice, but I think it becomes tricky once you're dealing with combined flags ( |
First off, the serialization is straightforward - just follow the same logic as
For deserialization, it certainly feels possible. I could see two approaches:
Both approaches seem to be pretty consistent, and I don't find them tricky. Just a matter of how generic we want this to be. |
I didn't see the The most reasonable implementation is using a string IMO. Would be nice to hear some other opinions. |
It doesn't matter, really, if this one is not straightforward. My point is - the code is already there, we just need to reuse it. In the worst case, the serializer can always bail out and write the bits directly (like it does today), with an ability to improve later. So I don't see this being a problem. |
I've implemented the requested logic in a wrapper macro: https://github.com/kvark/bitflags-serial If you'd like to move the code into |
@alexcrichton @dtolnay need your input here ^ |
This is better / more generic, right? I would almost call the current behavior a bug. If my rust code changes values but keeps the label constant, deserializing from storage will set the correct flags. With the current serialization the wrong flags will be set. |
@LegNeato I don't find this to be more generic. The main gain is convenience (for an ability to use constants by names instead of values). I do agree that the current behavior can be error prone though. |
1954: [dx12] layer clears r=msiglreith a=kvark Fixes #1943, works around #1945 PR checklist: - [ ] `make` succeeds (on *nix) - [x] `make reftests` succeeds - [x] tested examples with the following backends: dx12 I found out that we didn't update the raw bit flag values in reftests after one of the recent changes... Unfortunate, but this is more of a bitflags issue than ours, and I'm pushing upstream to resolve this in bitflags/bitflags#147 Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
Can we get some movement on this? Maintaining a fork of bitflags doesn't sound appealing to me. |
If it's possible for us to support this without breaking existing serialized values (I think non-self-describing formats like Note though that our Debug implementation is slightly broken in #137. Now that #220 is merged though, it could be possible to come up with a generic implementation over that that you could use with |
One of the goals of our |
This is supported in
|
Currently, serializing any bit flags into a text format isn't exactly readable:
It would be super useful to support given constants for deserialization (and potentially serialization too?), making this:
I don't know if it's best to approach this problem within the implementation of
derive(Deserialize)
macro in the rust repo, user-side things likederivative
, implementation of particular format in use (RON), or by changes in this care. Filing the issue here because bitflags are the strongest example for the case.The text was updated successfully, but these errors were encountered: