diff --git a/packages/cw-storey/tests/smoke_test.rs b/packages/cw-storey/tests/smoke_test.rs index bcd7057..4aece9a 100644 --- a/packages/cw-storey/tests/smoke_test.rs +++ b/packages/cw-storey/tests/smoke_test.rs @@ -6,12 +6,12 @@ use cosmwasm_std::Storage as _; fn smoke_test() { let mut storage = CwStorage(cosmwasm_std::testing::MockStorage::new()); - let item1 = Item::::new(&[0]); + let item1 = Item::::new(0); item1.access(&mut storage).set(&42).unwrap(); assert_eq!(item1.access(&storage).get().unwrap(), Some(42)); - let item2 = Item::::new(&[1]); + let item2 = Item::::new(1); assert_eq!(item2.access(&storage).get().unwrap(), None); assert_eq!(storage.0.get(&[0]), Some(vec![42])); diff --git a/packages/storey/src/containers/column.rs b/packages/storey/src/containers/column.rs index ad84a13..87cee38 100644 --- a/packages/storey/src/containers/column.rs +++ b/packages/storey/src/containers/column.rs @@ -35,7 +35,7 @@ const META_LEN: &[u8] = &[1]; /// assert_eq!(access.get(2).unwrap(), None); /// ``` pub struct Column { - prefix: &'static [u8], + prefix: u8, phantom: PhantomData<(T, E)>, } @@ -50,7 +50,7 @@ where /// with other keys in the storage. /// /// The key provided here is used as a prefix for all keys the column itself might generate. - pub const fn new(prefix: &'static [u8]) -> Self { + pub const fn new(prefix: u8) -> Self { Self { prefix, phantom: PhantomData, @@ -76,7 +76,7 @@ where /// let mut access = column.access(&mut storage); /// ``` pub fn access(&self, storage: S) -> ColumnAccess> { - Self::access_impl(StorageBranch::new(storage, self.prefix.to_vec())) + Self::access_impl(StorageBranch::new(storage, vec![self.prefix])) } } @@ -396,7 +396,7 @@ mod tests { fn basic() { let mut storage = TestStorage::new(); - let column = Column::::new(&[0]); + let column = Column::::new(0); let mut access = column.access(&mut storage); access.push(&1337).unwrap(); @@ -420,7 +420,7 @@ mod tests { fn iteration() { let mut storage = TestStorage::new(); - let column = Column::::new(&[0]); + let column = Column::::new(0); let mut access = column.access(&mut storage); access.push(&1337).unwrap(); diff --git a/packages/storey/src/containers/item.rs b/packages/storey/src/containers/item.rs index 68bba2a..61b32a2 100644 --- a/packages/storey/src/containers/item.rs +++ b/packages/storey/src/containers/item.rs @@ -24,7 +24,7 @@ use super::Storable; /// assert_eq!(item.access(&storage).get().unwrap(), Some(42)); /// ``` pub struct Item { - prefix: &'static [u8], + key: u8, phantom: PhantomData<(T, E)>, } @@ -36,9 +36,9 @@ where /// Create a new item with the given key. /// /// It is the responsibility of the caller to ensure that the key is unique. - pub const fn new(prefix: &'static [u8]) -> Self { + pub const fn new(key: u8) -> Self { Self { - prefix, + key, phantom: PhantomData, } } @@ -61,7 +61,7 @@ where /// let item = Item::::new(&[0]); /// let mut access = item.access(&mut storage); pub fn access(&self, storage: S) -> ItemAccess> { - Self::access_impl(StorageBranch::new(storage, self.prefix.to_vec())) + Self::access_impl(StorageBranch::new(storage, vec![self.key])) } } @@ -188,10 +188,10 @@ mod tests { fn basic() { let mut storage = TestStorage::new(); - let item0 = Item::::new(&[0]); + let item0 = Item::::new(0); item0.access(&mut storage).set(&42).unwrap(); - let item1 = Item::::new(&[1]); + let item1 = Item::::new(1); let access1 = item1.access(&storage); assert_eq!(item0.access(&storage).get().unwrap(), Some(42)); diff --git a/packages/storey/src/containers/map.rs b/packages/storey/src/containers/map.rs index c91de66..dd8bc71 100644 --- a/packages/storey/src/containers/map.rs +++ b/packages/storey/src/containers/map.rs @@ -43,7 +43,7 @@ use super::Storable; /// assert_eq!(access.entry("foo").entry("baz").get().unwrap(), None); /// ``` pub struct Map { - prefix: &'static [u8], + prefix: u8, phantom: PhantomData<(*const K, V)>, } @@ -59,7 +59,7 @@ where /// with other keys in the storage. /// /// The key provided here is used as a prefix for all keys managed by the map. - pub const fn new(prefix: &'static [u8]) -> Self { + pub const fn new(prefix: u8) -> Self { Self { prefix, phantom: PhantomData, @@ -85,7 +85,7 @@ where /// let mut access = map.access(&mut storage); /// ``` pub fn access(&self, storage: S) -> MapAccess> { - Self::access_impl(StorageBranch::new(storage, self.prefix.to_vec())) + Self::access_impl(StorageBranch::new(storage, vec![self.prefix])) } } @@ -313,7 +313,7 @@ mod tests { fn map() { let mut storage = TestStorage::new(); - let map = Map::>::new(&[0]); + let map = Map::>::new(0); map.access(&mut storage) .entry_mut("foo") @@ -332,7 +332,7 @@ mod tests { fn pairs() { let mut storage = TestStorage::new(); - let map = Map::>::new(&[0]); + let map = Map::>::new(0); let mut access = map.access(&mut storage); access.entry_mut("foo").set(&1337).unwrap(); @@ -355,7 +355,7 @@ mod tests { fn keys() { let mut storage = TestStorage::new(); - let map = Map::>::new(&[0]); + let map = Map::>::new(0); let mut access = map.access(&mut storage); access.entry_mut("foo").set(&1337).unwrap(); @@ -372,7 +372,7 @@ mod tests { fn values() { let mut storage = TestStorage::new(); - let map = Map::>::new(&[0]); + let map = Map::>::new(0); let mut access = map.access(&mut storage); access.entry_mut("foo").set(&1337).unwrap(); diff --git a/packages/storey/tests/composition.rs b/packages/storey/tests/composition.rs index 70a36bb..221df8c 100644 --- a/packages/storey/tests/composition.rs +++ b/packages/storey/tests/composition.rs @@ -8,7 +8,7 @@ use storey_storage::Storage as _; fn map_of_map() { let mut storage = TestStorage::new(); - let map = Map::>>::new(&[0]); + let map = Map::>>::new(0); map.access(&mut storage) .entry_mut("foo") @@ -42,7 +42,7 @@ fn map_of_map() { fn map_of_column() { let mut storage = TestStorage::new(); - let map = Map::>::new(&[0]); + let map = Map::>::new(0); let mut access = map.access(&mut storage); access.entry_mut("foo").push(&1337).unwrap(); diff --git a/packages/storey/tests/iteration.rs b/packages/storey/tests/iteration.rs index d7a3d4a..215f690 100644 --- a/packages/storey/tests/iteration.rs +++ b/packages/storey/tests/iteration.rs @@ -7,7 +7,7 @@ use mocks::encoding::TestEncoding; fn map_of_map_iteration() { let mut storage = TestStorage::new(); - let map = Map::>>::new(&[0]); + let map = Map::>>::new(0); let mut access = map.access(&mut storage); // populate with data