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

Serde support #48

Merged
merged 1 commit into from
Mar 30, 2016
Merged

Serde support #48

merged 1 commit into from
Mar 30, 2016

Conversation

dtolnay
Copy link
Contributor

@dtolnay dtolnay commented Mar 20, 2016

Serde is a serialization framework that converts Rust data structures to and from a variety of formats: JSON, YAML, TOML, XML, MessagePack, Bincode.

This commit adds two impls that allow Serde to serialize and deserialize a LinkedHashMap with any data format supported by Serde. I have put the impls behind a feature to avoid an unwanted dependency for people not using Serde.

LinkedHashMap will be valuable to users who need to read a JSON document and preserve the order of keys in a map, or write a JSON document and control the order of map keys in the output.

@FlashCat
Copy link
Contributor

Thanks for the pull request, and welcome! The contain-rs team is excited to review your changes, and you should hear from @reem (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

@@ -16,4 +16,10 @@ keywords = ["data-structures"]
readme = "README.md"

[features]
nightly = []
nightly = ["serde"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the nightly feature shouldn't enable serde.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. I fixed it in 2d5319d. EDIT: 30751e8 EDIT: how does quoting work 😢 give me a minute.

FINAL EDIT: this is what worked - 507caa0

@apasel422
Copy link
Contributor

The Travis stuff should probably be changed to something like

        - rust: beta
          env: FEATURES="serde"
        - rust: nightly
          env: FEATURES="nightly serde"
script:
    - cargo build --features $FEATURES
    - cargo test --features $FEATURES
    - cargo doc --no-deps --features $FEATURES

@dtolnay
Copy link
Contributor Author

dtolnay commented Mar 20, 2016

There are some other options if this is going to cause too much complexity to put here. I could keep the impls here (untested) and move the tests into the Serde repo, or move both the impls and the tests into Serde. I understand if you want to keep this project minimal.

@apasel422
Copy link
Contributor

What if you do something like was done in contain-rs/vec-map#15 and add a Cargo feature that enables both serde and serde_json, and have those both as optional non-dev dependencies?

@dtolnay
Copy link
Contributor Author

dtolnay commented Mar 20, 2016

Done. I don't like "eders" because linked-hash-map = { version = "*", features = ["eders"] } is impossible to guess what it means, but I added a "serde_impl" feature that enables both the impls and the tests. Without serde_impl, both cargo build and cargo test will continue to work as before.

@apasel422
Copy link
Contributor

Excellent. If you can squash the commits, this should be good to merge.

@dtolnay
Copy link
Contributor Author

dtolnay commented Mar 20, 2016

Done. Thanks for the quick review.

Serde[1] is a serialization framework that converts Rust
data structures to and from a variety of formats: JSON,
YAML, TOML, XML, MessagePack, Bincode.

This commit adds two impls that allow Serde to serialize and
deserialize a LinkedHashMap with any data format supported
by Serde. I have put the impls behind a feature to avoid an
unwanted dependency for people not using Serde.

LinkedHashMap will be valuable to users who need to read a
JSON document and preserve the order of keys in a map, or
write a JSON document and control the order of map keys in
the output.

[1]: https://github.com/serde-rs/serde
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants