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 Sep 23, 2023
1 parent 2da0584 commit 1c8c9b4
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 @@ -828,6 +828,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 @@ -1008,3 +1009,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 1c8c9b4

Please sign in to comment.