-
Notifications
You must be signed in to change notification settings - Fork 8
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
Conversation
Codecov Report
|
There was a problem hiding this 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.
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))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bag.serialize_element(&(&entry, &count))?; | |
bag.serialize_element(&(entry, &count))?; |
entry
is already a &T
— no need to take a further reference.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent, thanks!
Published in 0.1.5 🎉 |
This adds serialization and deserialization support via serde. This is done through an intermediate type that wraps each instance of
T
with its count.