json
json copied to clipboard
Exposing Number Kind
I have been working on a json-to-struct generator for a project, and I ran into an issue that I did not actually know the type of number. It would be useful to expose the type of the Number.
For reference: https://github.com/serde-rs/json/blob/master/src/number.rs#L17-L32
After discussion with @oli-obk we came to the following possibilities:
- Making
Number::n
andN
pub https://play.rust-lang.org/?gist=76af67ced7d5a9ff3aad1d0a10878b46&version=stable - Introducing a
NumberKind
type and implementing akind()
function onNumber
https://play.rust-lang.org/?gist=017cb7efe26cd6bf9a2b6b35f0f76dce&version=stable - Merging
N
intoNumber
, makingNumber
the enum itself https://play.rust-lang.org/?gist=ee1d87a959c1e3d8da982418222b65ac&version=stable
I would be on board with 2. The issue with 1 and 3 is they make it impossible to later reimplement using an arbitrary precision number library, which would be necessary in some use cases for dealing with numbers that don't fit in 64 bits.