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

Allow encoding/decoding of HashMap and HashSet with custom hash algorithms #529

Merged
merged 1 commit into from
Mar 28, 2022

Conversation

bronsonp
Copy link
Contributor

The current implementations of Encode and Decode for HashMap and HashSet are only defined for the default hash algorithm. However, these types also allow a custom hash type to be defined. At present, maps and sets using custom hashers cannot be handled by bincode.

This pull request adds the necessary functionality to support custom hash algorithms. The main change is the use of with_capacity_and_hasher instead of with_capacity when creating the new object in the Decode implementation.

The pull request also adds test cases in tests/std.rs to ensure that both HashMap and HashSet with custom hash algorithms can be handled successfully.

@codecov
Copy link

codecov bot commented Mar 28, 2022

Codecov Report

Merging #529 (ba290c5) into trunk (650fa39) will increase coverage by 0.14%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##            trunk     #529      +/-   ##
==========================================
+ Coverage   71.02%   71.16%   +0.14%     
==========================================
  Files          47       47              
  Lines        3182     3198      +16     
==========================================
+ Hits         2260     2276      +16     
  Misses        922      922              
Impacted Files Coverage Δ
src/features/impl_std.rs 79.88% <100.00%> (+0.24%) ⬆️
tests/std.rs 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 650fa39...ba290c5. Read the comment docs.

Copy link
Contributor

@VictorKoenders VictorKoenders left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks! 👍

@VictorKoenders VictorKoenders merged commit 18de104 into bincode-org:trunk Mar 28, 2022
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