From f0cfa5c474b63cecd392ed209a2881822261c8fb Mon Sep 17 00:00:00 2001 From: Jakub Bogucki Date: Mon, 15 Nov 2021 11:13:39 +0100 Subject: [PATCH] Replace previous iter implementation on key type in Map --- packages/storage-plus/src/helpers.rs | 4 ++-- packages/storage-plus/src/keys.rs | 3 ++- packages/storage-plus/src/map.rs | 8 ++------ 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/storage-plus/src/helpers.rs b/packages/storage-plus/src/helpers.rs index 8c713d182..6f566ea2e 100644 --- a/packages/storage-plus/src/helpers.rs +++ b/packages/storage-plus/src/helpers.rs @@ -22,7 +22,7 @@ pub(crate) fn may_deserialize( value: &Option>, ) -> StdResult> { match value { - Some(vec) => Ok(Some(from_slice(&vec)?)), + Some(vec) => Ok(Some(from_slice(vec)?)), None => Ok(None), } } @@ -30,7 +30,7 @@ pub(crate) fn may_deserialize( /// must_deserialize parses json bytes from storage (Option), returning NotFound error if no data present pub(crate) fn must_deserialize(value: &Option>) -> StdResult { match value { - Some(vec) => from_slice(&vec), + Some(vec) => from_slice(vec), None => Err(StdError::not_found(type_name::())), } } diff --git a/packages/storage-plus/src/keys.rs b/packages/storage-plus/src/keys.rs index 204b2bf9c..4566cddab 100644 --- a/packages/storage-plus/src/keys.rs +++ b/packages/storage-plus/src/keys.rs @@ -202,7 +202,7 @@ impl<'a> PrimaryKey<'a> for Vec { type SuperSuffix = Self; fn key(&self) -> Vec { - vec![Key::Ref(&self)] + vec![Key::Ref(self)] } } @@ -572,6 +572,7 @@ mod test { #[test] fn proper_prefixes() { let simple: &str = "hello"; + assert_eq!(simple.prefix().len(), 1); assert_eq!(simple.prefix()[0].as_ref(), b"hello"); let pair: (U32Key, &[u8]) = (12345.into(), b"random"); diff --git a/packages/storage-plus/src/map.rs b/packages/storage-plus/src/map.rs index 650a278e2..2ac1fe0b1 100644 --- a/packages/storage-plus/src/map.rs +++ b/packages/storage-plus/src/map.rs @@ -9,7 +9,7 @@ use crate::helpers::query_raw; use crate::iter_helpers::{deserialize_kv, deserialize_v}; #[cfg(feature = "iterator")] use crate::keys::Prefixer; -use crate::keys::PrimaryKey; +use crate::keys::{Key, PrimaryKey}; use crate::path::Path; #[cfg(feature = "iterator")] use crate::prefix::{namespaced_prefix_range, Bound, Prefix, PrefixBound}; @@ -45,11 +45,7 @@ where pub fn key(&self, k: K) -> Path { Path::new( self.namespace, - &k.key() - .iter() - .map(|e| e.as_ref()) - .collect::>() - .as_slice(), + &k.key().iter().map(Key::as_ref).collect::>(), ) }