-
Notifications
You must be signed in to change notification settings - Fork 132
Control integer representations #144
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
Comments
Can you control the definition of the struct? I'd just use a custom path: pub struct MyStruct {
#[serde(with = "hex")]
flags: usize,
}
mod hex {
// pseudo code
fn serialize<S>(flags: &usize, ser: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let flags = flags.to_hex_string();
ser.serialize_str(&flags)
}
// fn deserialize
} |
@kvark Does this work for your use case? |
Trouble is that in WebRender the same structure may need to be serialized with both bincode and RON. And I only want RON to be showing the hex representation, of course. |
Okay, I understand. So you want to set the representation of all integers globally? |
@torkleyy nope, not all integers, just a particular field of a particular struct. |
Okay. So given that werde doesn’t support that, the only option I see would be to configure overrides for the serializer. Something like serializer.for_field(“flags”, Repr::Hex); which... seems very special case-y. |
That's an interesting approach, and while inconvenient, it's certainly at least an option for us to proceed. I'd say let's expose this in some way. |
The serialized structure can also look at |
Issue has had no activity in the last 180 days and is going to be closed in 7 days if no further activity occurs |
It would be good to be able to say that a particular integer needs to be serialized in hex, for example. On first approximation, this doesn't appear to be possible through serde attributes, since serde doesn't care about how integers are parsed.
The text was updated successfully, but these errors were encountered: