Add forgotten deserialize and default to a valid page size

master
gramar 2 years ago
parent 4aa44bc9ac
commit a0e7399d09

@ -216,11 +216,18 @@ where K: Collapse
// TODO: Replace with `SmallVec<[Page<TKey, TValue>; 1]>` when feature that adds `smallvec` is enabled (this will allocate the first page on the stack, and the rest on the heap. // TODO: Replace with `SmallVec<[Page<TKey, TValue>; 1]>` when feature that adds `smallvec` is enabled (this will allocate the first page on the stack, and the rest on the heap.
pub struct Map<TKey, TValue>(Vec<Page<TKey,TValue>>); pub struct Map<TKey, TValue>(Vec<Page<TKey,TValue>>);
#[derive(Default)] #[cfg(feature = "serde")]
struct MapVisitor<TKey, TValue> { struct MapVisitor<TKey, TValue> {
_pd: core::marker::PhantomData<(TKey, TValue)>, _pd: core::marker::PhantomData<(TKey, TValue)>,
} }
#[cfg(feature = "serde")]
impl<'de, TKey, TValue> serde::de::Deserialize<'de> for Map<TKey, TValue> where TKey: Collapse + serde::Deserialize<'de>, TValue: serde::Deserialize<'de> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de> {
deserializer.deserialize_map(MapVisitor { _pd: core::marker::PhantomData::default() })
}
}
/// Just taken from [serde.rs' examples](https://serde.rs/deserialize-map.html) /// Just taken from [serde.rs' examples](https://serde.rs/deserialize-map.html)
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
impl<'de, TKey, TValue> serde::de::Visitor<'de> for MapVisitor<TKey, TValue> where TKey: Collapse + serde::Deserialize<'de>, TValue: serde::Deserialize<'de> { impl<'de, TKey, TValue> serde::de::Visitor<'de> for MapVisitor<TKey, TValue> where TKey: Collapse + serde::Deserialize<'de>, TValue: serde::Deserialize<'de> {
@ -231,7 +238,7 @@ impl<'de, TKey, TValue> serde::de::Visitor<'de> for MapVisitor<TKey, TValue> whe
} }
fn visit_map<A>(self, mut access: A) -> Result<Self::Value, A::Error> where A: serde::de::MapAccess<'de> { fn visit_map<A>(self, mut access: A) -> Result<Self::Value, A::Error> where A: serde::de::MapAccess<'de> {
let mut map = Map::with_capacity(access.size_hint().unwrap_or(0)); let mut map = Map::with_capacity(access.size_hint().unwrap_or(1));
while let Some((key, value)) = access.next_entry()? { while let Some((key, value)) = access.next_entry()? {
map.insert(key, value); map.insert(key, value);
} }

Loading…
Cancel
Save