rust-gmp
rust-gmp copied to clipboard
Adding serde support feature for Mpz
We needed serde for Mpz in one of our upper layer (dependency). Here is a PR if you are interested, I added it as a feature.
cargo build --features "serde_support"
cargo test --features "serde_support"
Thanks,
I’m not sure it makes sense as a global default to serialize to hexadecimal.
Yes I agree. In my use case it ends up being serialized to JSON and propagated to an upper layer. Hex is good for readability. What would you suggest?
At least Python and Java will happily serialize a big integer to JSON as an unquoted decimal number:
808017424794512875886459904961710757005754368000000000
which is perfectly fine as far as the JSON grammar is concerned, even though such values will not (yet?) round-trip through JavaScript. There is also a de facto convention of sending quoted decimal numbers where JavaScript interoperability is important:
"808017424794512875886459904961710757005754368000000000"
Twitter notably decided screw it, we’ll do both.
You can of course override the default behavior to whatever you want with a newtype wrapper, so the question here is what makes sense as a default.
I think unquoted decimal makes the most sense for Rust, which doesn’t have to worry about confusing big integers as approximate floats. Quoted decimal would be an understandable compromise if there are good reasons for it. But I don’t know of any widespread convention involving hexadecimal, and I’d find it especially strange to see hexadecimal without a 0x
prefix.
You made this PR from your master
branch, which you are now using for unrelated commits. Time to close this PR?