From d1360bbec0ff36caa2d5e6b2f0e2b47a5123a46f Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Sat, 26 Nov 2022 17:13:51 +0100 Subject: [PATCH] crdt: Remove `Copy` bound on `LWWMap` Signed-off-by: Alexis Sellier --- radicle-crdt/src/lwwmap.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/radicle-crdt/src/lwwmap.rs b/radicle-crdt/src/lwwmap.rs index 20bfa24c..dceb0e1b 100644 --- a/radicle-crdt/src/lwwmap.rs +++ b/radicle-crdt/src/lwwmap.rs @@ -10,7 +10,7 @@ pub struct LWWMap { inner: BTreeMap, C>>, } -impl LWWMap { +impl LWWMap { pub fn singleton(key: K, value: V, clock: C) -> Self { Self { inner: BTreeMap::from_iter([(key, LWWReg::new(Some(value), clock))]), @@ -37,10 +37,14 @@ impl LWWMa } pub fn remove(&mut self, key: K, clock: C) { - self.inner - .entry(key) - .and_modify(|reg| reg.set(None, clock)) - .or_insert_with(|| LWWReg::new(None, clock)); + match self.inner.entry(key) { + Entry::Occupied(mut e) => { + e.get_mut().set(None, clock); + } + Entry::Vacant(e) => { + e.insert(LWWReg::new(None, clock)); + } + } } pub fn contains_key(&self, key: K) -> bool {