It seems like non-self-describing formats (ie postcard, bincode) require a sized sequence when serializing. papaya::HashMap obviously can't provide a bounded size_hint (which would make serde's collect_map work as is) due to concurrent access. I've worked around this via
fn serialize_papaya_map<S, K, V>(map: &HashMap<K, V>, serializer: S) -> StdResult<S::Ok, S::Error>
where
S: Serializer,
K: Serialize + core::hash::Hash + Eq,
V: Serialize,
{
serializer.collect_seq(map.pin().iter().collect::<Vec<_>>())
}
fn deserialize_papaya_map<'de, D, K, V>(deserializer: D) -> StdResult<HashMap<K, V>, D::Error>
where
D: Deserializer<'de>,
K: Deserialize<'de> + core::hash::Hash + Eq,
V: Deserialize<'de>,
{
let entries: Vec<(K, V)> = Vec::deserialize(deserializer)?;
let map = HashMap::new();
for (k, v) in entries {
map.pin().insert(k, v);
}
Ok(map)
}
If you don't want to bring that into the lib, it may be helpful to others to document the incompatibility due to concurrency here and suggest a similar workaround to what I've done. I can PR that if it's the way you'd like to approach it.
It seems like non-self-describing formats (ie postcard, bincode) require a sized sequence when serializing.
papaya::HashMapobviously can't provide a boundedsize_hint(which would make serde'scollect_mapwork as is) due to concurrent access. I've worked around this viaIf you don't want to bring that into the lib, it may be helpful to others to document the incompatibility due to concurrency here and suggest a similar workaround to what I've done. I can PR that if it's the way you'd like to approach it.