Skip to content

Commit

Permalink
feat: implement serde for FrozenBTreeMap
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Aug 10, 2023
1 parent 819122e commit a42fa30
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,7 @@ fn test_non_lockfree() {
/// Append-only threadsafe version of `std::collections::BTreeMap` where
/// insertion does not require mutable access
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(Serialize))]
pub struct FrozenBTreeMap<K, V>(RwLock<BTreeMap<K, V>>);

impl<K: Clone + Ord, V: StableDeref> FrozenBTreeMap<K, V> {
Expand Down Expand Up @@ -931,3 +932,11 @@ impl<K: Clone + Ord, V: StableDeref> Default for FrozenBTreeMap<K, V> {
Self::new()
}
}

#[cfg(feature = "serde")]
impl<'de> Deserialize<'de> for FrozenBTreeMap<String, String> {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
let map = BTreeMap::<String, String>::deserialize(deserializer)?;
Ok(map.into())
}
}

0 comments on commit a42fa30

Please sign in to comment.