From f5a0cf0414fc3db7affcbe7ffcf4e251a2afd192 Mon Sep 17 00:00:00 2001 From: Trinity Pointard Date: Fri, 23 Apr 2021 21:42:52 +0200 Subject: fix clippy warnings on table --- src/table/crdt/crdt.rs | 6 ++---- src/table/crdt/lww_map.rs | 18 +++++++++++++++++- src/table/crdt/map.rs | 15 +++++++++++++++ src/table/crdt/mod.rs | 1 + 4 files changed, 35 insertions(+), 5 deletions(-) (limited to 'src/table/crdt') diff --git a/src/table/crdt/crdt.rs b/src/table/crdt/crdt.rs index 636b6df6..7abe8ba9 100644 --- a/src/table/crdt/crdt.rs +++ b/src/table/crdt/crdt.rs @@ -52,10 +52,8 @@ where *self = other.clone(); } warn!("Making an arbitrary choice: {:?}", self); - } else { - if other > self { - *self = other.clone(); - } + } else if other > self { + *self = other.clone(); } } } diff --git a/src/table/crdt/lww_map.rs b/src/table/crdt/lww_map.rs index 7b372191..4ed26809 100644 --- a/src/table/crdt/lww_map.rs +++ b/src/table/crdt/lww_map.rs @@ -94,7 +94,7 @@ where /// put_my_crdt_value(a); /// ``` pub fn take_and_clear(&mut self) -> Self { - let vals = std::mem::replace(&mut self.vals, vec![]); + let vals = std::mem::take(&mut self.vals); Self { vals } } /// Removes all values from the map @@ -113,10 +113,16 @@ where pub fn items(&self) -> &[(K, u64, V)] { &self.vals[..] } + /// Returns the number of items in the map pub fn len(&self) -> usize { self.vals.len() } + + /// Returns true if the map is empty + pub fn is_empty(&self) -> bool { + self.len() == 0 + } } impl CRDT for LWWMap @@ -143,3 +149,13 @@ where } } } + +impl Default for LWWMap +where + K: Ord, + V: CRDT, +{ + fn default() -> Self { + Self::new() + } +} diff --git a/src/table/crdt/map.rs b/src/table/crdt/map.rs index c4a30a26..c4dd1613 100644 --- a/src/table/crdt/map.rs +++ b/src/table/crdt/map.rs @@ -62,6 +62,11 @@ where pub fn len(&self) -> usize { self.vals.len() } + + /// Returns true if the map is empty + pub fn is_empty(&self) -> bool { + self.len() == 0 + } } impl CRDT for Map @@ -82,3 +87,13 @@ where } } } + +impl Default for Map +where + K: Clone + Ord, + V: Clone + CRDT, +{ + fn default() -> Self { + Self::new() + } +} diff --git a/src/table/crdt/mod.rs b/src/table/crdt/mod.rs index eb75d061..9663a5a5 100644 --- a/src/table/crdt/mod.rs +++ b/src/table/crdt/mod.rs @@ -10,6 +10,7 @@ //! Learn more about CRDT [on Wikipedia](https://en.wikipedia.org/wiki/Conflict-free_replicated_data_type) mod bool; +#[allow(clippy::module_inception)] mod crdt; mod lww; mod lww_map; -- cgit v1.2.3