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

Added Serde support #5

Merged
merged 7 commits into from
Mar 20, 2022
Merged

Added Serde support #5

merged 7 commits into from
Mar 20, 2022

Conversation

TylerBloom
Copy link
Contributor

This adds serialization and deserialization support via serde. This is done through an intermediate type that wraps each instance of T with its count.

@codecov
Copy link

codecov bot commented Mar 10, 2022

Codecov Report

Merging #5 (9fc7127) into master (4ff8b4c) will decrease coverage by 6.1%.
The diff coverage is 7.1%.

Impacted Files Coverage Δ
src/serde.rs 0.0% <0.0%> (ø)
src/lib.rs 95.1% <100.0%> (+<0.1%) ⬆️

Copy link
Owner

@jonhoo jonhoo left a comment

Choose a reason for hiding this comment

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

Thanks for taking the time to do this! I left a few notes inline.

Cargo.toml Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/with_serde.rs Outdated Show resolved Hide resolved
src/with_serde.rs Outdated Show resolved Hide resolved
src/with_serde.rs Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/serde.rs Outdated Show resolved Hide resolved
src/serde.rs Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/serde.rs Show resolved Hide resolved
src/serde.rs Outdated
let mut bag = serializer.serialize_seq(Some(self.len()))?;

for (entry, count) in self.set_iter() {
bag.serialize_element(&(&entry, &count))?;
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
bag.serialize_element(&(&entry, &count))?;
bag.serialize_element(&(entry, &count))?;

entry is already a &T — no need to take a further reference.

src/serde.rs Outdated Show resolved Hide resolved
src/serde.rs Show resolved Hide resolved
src/serde.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated
@@ -12,6 +12,10 @@
//! If you want to use a hash table with [amortized resizes](https://github.com/jonhoo/griddle/),
//! set the `amortize` feature.
//!
//! (De)serialization via serde is also available with the `serde` feature.
//! Serialization note: if the incoming data has repeated keys, the resulting `HashBag` will merge
Copy link
Owner

Choose a reason for hiding this comment

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

Would you mind adding a test for this behavior too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added two tests to mirror the other tests. I also corrected my wording here. We are not concerned about communicating how we serialize a HashBag, only how we deserialize one.

#[test]
fn repeat_simple_entries() {
let jsonified_vikings: String =
"[[\"Einar\",1],[\"Olaf\",1],[\"Olaf\",1],[\"Harald\",2],[\"Harald\",1]]".to_string();
Copy link
Owner

Choose a reason for hiding this comment

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

Just a tip: you can use raw string literals to avoid all the \" in there :)

Copy link
Owner

@jonhoo jonhoo left a comment

Choose a reason for hiding this comment

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

Excellent, thanks!

@jonhoo jonhoo merged commit ebd5635 into jonhoo:master Mar 20, 2022
@jonhoo
Copy link
Owner

jonhoo commented Mar 20, 2022

Published in 0.1.5 🎉

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.

2 participants