evmap icon indicating copy to clipboard operation
evmap copied to clipboard

Implement Serialize for MapReadRef

Open elichai opened this issue 3 years ago • 5 comments

This solves #2

I tried also implementing serde::Deserialize for (WriteHandle, ReadHandle) but apparently implementing a foreign trait on a tuple with generic structs violates the orphan rule.

note that this can't be collected into a Hashmap<K,V> but into a HashMap<K, Vec<V>>

elichai avatar Jun 21 '21 15:06 elichai

Codecov Report

Merging #8 (a2f55b0) into master (557feab) will decrease coverage by 2.48%. The diff coverage is 0.00%.

Impacted Files Coverage Δ
src/read/read_ref.rs 54.16% <0.00%> (-6.30%) :arrow_down:
src/values.rs 79.50% <0.00%> (-6.22%) :arrow_down:

codecov-commenter avatar Jun 21 '21 15:06 codecov-commenter

Should I enable the serde feature in the CI? Should I write some tests for this? (I didn't write because that will require deciding which dependency to use, serde_json or a more complex serde_test suite)

elichai avatar Jun 21 '21 15:06 elichai

This is great, thanks!

For Deserialize, I wonder if we can't just implement it for WriteHandle specifically. It should be possible to get a new ReadHandle given just a WriteHandle, so as long as we can deserialize into a WriteHandle, that should get you most of the way. The implementation is (hopefully) also very simply — just deserialize into a HashMap with the appropriate key/value type, and then turn that into a WriteHandle + ReadHandle, and then drop the ReadHandle.

jonhoo avatar Jun 22 '21 02:06 jonhoo

For Deserialize, I wonder if we can't just implement it for WriteHandle specifically. It should be possible to get a new ReadHandle given just a WriteHandle

I thought about doing that but assumed it's not correct, because all the current constructors return both a write and read handles.

elichai avatar Jun 22 '21 08:06 elichai

Ah, no, that should be entirely correct!

jonhoo avatar Jun 24 '21 02:06 jonhoo