Skip to content

Commit

Permalink
Replace previous iter implementation on key type in Map
Browse files Browse the repository at this point in the history
  • Loading branch information
ueco-jb committed Nov 15, 2021
1 parent 38c6a58 commit f0cfa5c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/storage-plus/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ pub(crate) fn may_deserialize<T: DeserializeOwned>(
value: &Option<Vec<u8>>,
) -> StdResult<Option<T>> {
match value {
Some(vec) => Ok(Some(from_slice(&vec)?)),
Some(vec) => Ok(Some(from_slice(vec)?)),
None => Ok(None),
}
}

/// must_deserialize parses json bytes from storage (Option), returning NotFound error if no data present
pub(crate) fn must_deserialize<T: DeserializeOwned>(value: &Option<Vec<u8>>) -> StdResult<T> {
match value {
Some(vec) => from_slice(&vec),
Some(vec) => from_slice(vec),
None => Err(StdError::not_found(type_name::<T>())),
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/storage-plus/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl<'a> PrimaryKey<'a> for Vec<u8> {
type SuperSuffix = Self;

fn key(&self) -> Vec<Key> {
vec![Key::Ref(&self)]
vec![Key::Ref(self)]
}
}

Expand Down Expand Up @@ -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");
Expand Down
8 changes: 2 additions & 6 deletions packages/storage-plus/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -45,11 +45,7 @@ where
pub fn key(&self, k: K) -> Path<T> {
Path::new(
self.namespace,
&k.key()
.iter()
.map(|e| e.as_ref())
.collect::<Vec<_>>()
.as_slice(),
&k.key().iter().map(Key::as_ref).collect::<Vec<_>>(),
)
}

Expand Down

0 comments on commit f0cfa5c

Please sign in to comment.