Repository navigation
Write and read JSON in Rust, by serde - #26
Merged
Merged
Conversation
…lize and Deserialize, as JSON_FORMAT.md has it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The generated Rust structs are written as JSON, and read from it, by serde: as JSON_FORMAT.md has it, which Python and C++ write and read.
json, each struct, enum and union isSerializeandDeserialize: so they are also what a Rust program gives any other format of serde's.dataclass_native::json::{to_json, from_json}write and read JSON.json!, which is of nothing without it. The featurepythonhas it.Form, and serde's traits by that, not by serde'sderive: as what the format has of a float which is not finite, or of bytes, it has wherever one is, as within a tuple. A plain union is read by the kind of value which is next, and of a string by which of its members reads it.__json__and__from_json__, as those of C++ have, so JSON of what is bound to Rust no longer goes by way of Python.Also, as asked: WIRE_FORMAT.md and JSON_FORMAT.md say that what is asked of the implementations is that each reads what any of them writes, not that they write the same.
On an Apple M1, of extensions built for release, in microseconds for each
Orderof the README's Performance section:pureRust reads otherwise than Python and C++ only what none of them writes:
-0is not an integer to serde, and is the float-0.0; and a key which is a number may have no spaces about it. Five cases of the test that each reads as the other does are of these, and are not run with the Rust extension. JSON_FORMAT.md says so.Tested by the tests of JSON which are for every mode, run with the extension; and by a program of Rust alone, which cargo now runs both without the feature and with it. Also checked, though not kept as a test: of 21 objects, Rust writes the bytes which the Python reference does; and of some 7,600 corruptions of them, Rust and C++ each took or rejected the same.
Arrow is still done by Python for what Rust holds, and is to follow.