From 03c314d908caaea52481307e5ea6d8db6b02e747 Mon Sep 17 00:00:00 2001 From: mulmarta <103590845+mulmarta@users.noreply.github.com> Date: Wed, 12 Jun 2024 20:43:50 +0200 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Stephane Raux <94983192+stefunctional@users.noreply.github.com> --- mls-rs/src/map.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/mls-rs/src/map.rs b/mls-rs/src/map.rs index 0c916841..f0104f58 100644 --- a/mls-rs/src/map.rs +++ b/mls-rs/src/map.rs @@ -19,7 +19,7 @@ mod map_impl { #[derive(Clone, Debug, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] - pub struct SmallMap(pub(super) HashMap); + pub struct SmallMap(pub(super) HashMap); pub type LargeMap = SmallMap; pub(super) type SmallMapInner = HashMap; @@ -38,14 +38,14 @@ mod map_impl { use itertools::Itertools; #[derive(Clone, Debug, PartialEq, Eq)] - pub struct SmallMap(pub(super) Vec<(K, V)>); + pub struct SmallMap(pub(super) Vec<(K, V)>); pub type LargeMap = BTreeMap; pub(super) type SmallMapInner = Vec<(K, V)>; pub type LargeMapEntry<'a, K, V> = Entry<'a, K, V>; #[cfg(feature = "by_ref_proposal")] - impl SmallMap { + impl SmallMap { pub fn get(&self, key: &K) -> Option<&V> { self.find(key).map(|i| &self.0[i].1) } @@ -64,19 +64,18 @@ mod map_impl { fn find(&self, key: &K) -> Option { self.0 .iter() - .find_position(|(k, _)| k == key) - .map(|(i, _)| i) + .position(|(k, _)| k == key) } } } -impl Default for SmallMap { +impl Default for SmallMap { fn default() -> Self { Self(SmallMapInner::new()) } } -impl Deref for SmallMap { +impl Deref for SmallMap { type Target = SmallMapInner; fn deref(&self) -> &Self::Target { @@ -84,7 +83,7 @@ impl Deref for SmallMap { } } -impl DerefMut for SmallMap { +impl DerefMut for SmallMap { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } @@ -92,7 +91,7 @@ impl DerefMut for SmallMap { impl MlsDecode for SmallMap where - K: Hash + Eq + PartialEq + MlsEncode + MlsDecode + MlsSize, + K: Hash + Eq + MlsEncode + MlsDecode + MlsSize, V: MlsEncode + MlsDecode + MlsSize, { fn mls_decode(reader: &mut &[u8]) -> Result { @@ -102,7 +101,7 @@ where impl MlsSize for SmallMap where - K: Hash + Eq + PartialEq + MlsEncode + MlsDecode + MlsSize, + K: Hash + Eq + MlsEncode + MlsDecode + MlsSize, V: MlsEncode + MlsDecode + MlsSize, { fn mls_encoded_len(&self) -> usize { @@ -112,7 +111,7 @@ where impl MlsEncode for SmallMap where - K: Hash + Eq + PartialEq + MlsEncode + MlsDecode + MlsSize, + K: Hash + Eq + MlsEncode + MlsDecode + MlsSize, V: MlsEncode + MlsDecode + MlsSize, { fn mls_encode(&self, writer: &mut Vec) -> Result<(), mls_rs_codec::Error> {