Re:Son: A minimal subset of JSON for machine-to-machine comm...
by colanderman on Sunday December 10, 2017 @03:07PM
(#15893235)
Wonderful. Good to know that about Rust, I haven't used it but everything I read about it looks good. Yes that is exactly the approach I meant (and a similar mechanism to that used by my own C++ JSON library I use for side projects).
Re:Son: A minimal subset of JSON for machine-to-machine comm...
by LambdaComplex on Sunday December 10, 2017 @01:33PM
(#15892736)
Doesn't most of the Rust ecosystem use serde though?
Re:Son: A minimal subset of JSON for machine-to-machine comm...
by steveklabnik on Sunday December 10, 2017 @02:09PM
(#15892926)
It looks like serde-json does the same: https://docs.serde.rs/serde_json/struct.Number.html
Re:Son: A minimal subset of JSON for machine-to-machine comm...
by chrismorgan on Sunday December 10, 2017 @10:20PM
(#15894922)
Well, not the same; it eagerly interprets it as PosInt(u64), NegInt(i64) or Float(f64) rather than storing the mantissa and exponent. This is enough for JavaScript compatibility (its Number type being essentially a 64-bit float), but it’s not quite as flexible as the json crate’s approach.
It stores it as positive, mantissa and exponent, allowing you to pull it apart in that way if you need to. Meanwhile, normal usage is via JsonValue (https://docs.rs/json/0.11.12/json/enum.JsonValue.html) which allows you to attempt to convert it into an f64, i32, u8, &c. as you desire, returning `None` if it doesn’t fit inside that type (e.g. -7 won’t go into an i32, 576 won’t go into a u8).
By what’s being talked about here, that looks to be a competent JSON implementation.