json icon indicating copy to clipboard operation
json copied to clipboard

Exposing Number Kind

Open VictorKoenders opened this issue 7 years ago • 1 comments

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:

  1. Making Number::n and N pub https://play.rust-lang.org/?gist=76af67ced7d5a9ff3aad1d0a10878b46&version=stable
  2. Introducing a NumberKind type and implementing a kind() function on Number https://play.rust-lang.org/?gist=017cb7efe26cd6bf9a2b6b35f0f76dce&version=stable
  3. Merging N into Number, making Number the enum itself https://play.rust-lang.org/?gist=ee1d87a959c1e3d8da982418222b65ac&version=stable

VictorKoenders avatar Oct 10 '17 08:10 VictorKoenders

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.

dtolnay avatar Oct 10 '17 13:10 dtolnay