From 1e1bd3afd87a683836355a78b3bc74db8e54314b Mon Sep 17 00:00:00 2001 From: Mauro Lacy Date: Tue, 9 Nov 2021 17:10:03 +0100 Subject: [PATCH] Add sub_/prefix_de to SnapshotMap for completeness --- packages/storage-plus/src/indexed_map.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/storage-plus/src/indexed_map.rs b/packages/storage-plus/src/indexed_map.rs index d1c831a30..0c2a084f9 100644 --- a/packages/storage-plus/src/indexed_map.rs +++ b/packages/storage-plus/src/indexed_map.rs @@ -196,6 +196,22 @@ where } } +#[cfg(feature = "iterator")] +impl<'a, K, T, I> IndexedMap<'a, K, T, I> +where + T: Serialize + DeserializeOwned + Clone, + K: PrimaryKey<'a>, + I: IndexList, +{ + pub fn sub_prefix_de(&self, p: K::SubPrefix) -> Prefix { + Prefix::new(self.pk_namespace, &p.prefix()) + } + + pub fn prefix_de(&self, p: K::Prefix) -> Prefix { + Prefix::new(self.pk_namespace, &p.prefix()) + } +} + #[cfg(feature = "iterator")] impl<'a, K, T, I> IndexedMap<'a, K, T, I> where @@ -220,7 +236,7 @@ where K: 'c, K::Output: 'static, { - let mapped = namespaced_prefix_range(store, self.primary.namespace(), min, max, order) + let mapped = namespaced_prefix_range(store, self.pk_namespace, min, max, order) .map(deserialize_kv::); Box::new(mapped) } @@ -254,7 +270,7 @@ where } fn no_prefix_de(&self) -> Prefix { - Prefix::new(self.primary.namespace(), &[]) + Prefix::new(self.pk_namespace, &[]) } }