Skip to content

Commit

Permalink
Add sub_/prefix_de to SnapshotMap for completeness
Browse files Browse the repository at this point in the history
  • Loading branch information
maurolacy committed Nov 9, 2021
1 parent 067fb5f commit 1e1bd3a
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions packages/storage-plus/src/indexed_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>,
{
pub fn sub_prefix_de(&self, p: K::SubPrefix) -> Prefix<K::SuperSuffix, T> {
Prefix::new(self.pk_namespace, &p.prefix())
}

pub fn prefix_de(&self, p: K::Prefix) -> Prefix<K::Suffix, T> {
Prefix::new(self.pk_namespace, &p.prefix())
}
}

#[cfg(feature = "iterator")]
impl<'a, K, T, I> IndexedMap<'a, K, T, I>
where
Expand All @@ -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::<K, T>);
Box::new(mapped)
}
Expand Down Expand Up @@ -254,7 +270,7 @@ where
}

fn no_prefix_de(&self) -> Prefix<K, T> {
Prefix::new(self.primary.namespace(), &[])
Prefix::new(self.pk_namespace, &[])
}
}

Expand Down

0 comments on commit 1e1bd3a

Please sign in to comment.