Navigation Menu

Skip to content
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

Arbitrary precision numbers #252

Closed
wants to merge 9 commits into from
Closed

Arbitrary precision numbers #252

wants to merge 9 commits into from

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented Feb 11, 2017

Fixes #18.

serde_json = { version = "0.9", features = ["arbitrary_precision"] }
#[derive(Serialize, Deserialize)]
struct S {
    n: serde_json::Number,
    v: serde_json::Value,
}

let s: S = serde_json::from_str(...)?;

// full precision
println!("{}", s.n);
println!("{}", s.v);
println!("{}", serde_json::to_string(&s)?);

@dtolnay dtolnay requested a review from oli-obk February 11, 2017 21:11
@dtolnay
Copy link
Member Author

dtolnay commented Feb 11, 2017

@alexreg please take a quick look at this and let us know whether it satisfies your use case.

@alexreg
Copy link
Contributor

alexreg commented Feb 12, 2017

A few name changes I would suggest for clarity/consistency:

ParseNumber -> Json(Number)Visitor
VisitNumber -> (Number)Visitor
SerializeNumber -> NumberSerializer

Take them or leave them. :)

@dtolnay
Copy link
Member Author

dtolnay commented Feb 13, 2017

Thanks for the idea. I would prefer to leave it as is. We use ...Visitor for things that implement the Visitor trait and ...Serializer for things that implement the Serializer trait, which is not the case here.

@dtolnay
Copy link
Member Author

dtolnay commented Feb 13, 2017

Waiting on #18 (comment).

@alexreg
Copy link
Contributor

alexreg commented Feb 13, 2017

Fair enough.

@dtolnay
Copy link
Member Author

dtolnay commented Feb 26, 2017

I am going to try to rework this to use the same trick that TOML uses for specialized handling of Datetimes without relying on specialization.

@dtolnay dtolnay closed this Feb 26, 2017
@dtolnay dtolnay deleted the numstr branch February 26, 2017 21:53
@alexreg
Copy link
Contributor

alexreg commented Feb 26, 2017

If it's using a "trick", I'd be very much against that! Nothing too hacky, please.

@dtolnay
Copy link
Member Author

dtolnay commented Feb 26, 2017

Let's call it "under-explored abilities of the API" rather than "trick."

@alexreg
Copy link
Contributor

alexreg commented Feb 26, 2017

Okay. I quite like the way it worked currently... so I hope it doesn't change too much!

@alexreg
Copy link
Contributor

alexreg commented Apr 1, 2017

Any update on this yet, @dtolnay?

@dtolnay
Copy link
Member Author

dtolnay commented Apr 2, 2017

Nope, will be post 1.0.

@alexreg
Copy link
Contributor

alexreg commented Apr 2, 2017

Okay. No chance of getting a feature-gated specialisation-based version before then? I don't know when 1.0 will be, but I guess soon-ish...

@dtolnay
Copy link
Member Author

dtolnay commented Apr 3, 2017

No chance of getting a feature-gated specialization-based version. We are making some lifetime-related changes in the next release (#288) and specialization interacts very poorly with lifetimes - use after free, corrupted data, etc. See rust-lang/rust#40582.

@alexreg
Copy link
Contributor

alexreg commented Jun 29, 2017

@dtolnay How about now? :)

alexreg added a commit to alexreg/serde-json that referenced this pull request Aug 22, 2017
… feature).

This effort was based in part on the work of @dtolnay in serde-rs#252 and @alexcrichton in https://github.com/alexcrichton/toml-rs.

Also updated test suite for `arbitrary_precision` feature.
alexreg added a commit to alexreg/serde-json that referenced this pull request Aug 22, 2017
… feature).

This effort was based in part on the work of @dtolnay in serde-rs#252 and @alexcrichton in https://github.com/alexcrichton/toml-rs.

Also updated test suite for `arbitrary_precision` feature.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

3 participants