Skip to content

Add FromResp impl for HashMap #29

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

Merged
merged 5 commits into from
Oct 16, 2018
Merged

Conversation

augustuswm
Copy link
Contributor

This PR adds an implementation of FromResp for HashMap. It takes an array response containing an even number of elements and treats it as a list of alternating key, value elements.

KEY1
VALUE1
KEY2
VALUE2

This can be used to transform the response of HGETALL into a HashMap<K, V> where K and V implement FromResp.

Not sure if this is in scope for this library, but here it is in case others find it useful.

Ran in to this in an exercise to try porting an existing project from redis-rs to redis-async-rs. Heavily inspired by https://docs.rs/redis/0.9.1/src/redis/types.rs.html#844-860

@benashford benashford merged commit d236736 into benashford:master Oct 16, 2018
@benashford
Copy link
Owner

Cool 😃

Thanks for this 👍

@benashford
Copy link
Owner

Published as 0.4.3

I made a small tweak which means it should work for HashMaps with other hashers, e.g. FnvHashMap from here: https://github.com/servo/rust-fnv but this is transparent to the calling code (i.e. the tests you added are unmodified and work the same way).

Thanks again.

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