diff --git a/crates/storage/Cargo.toml b/crates/storage/Cargo.toml index 77ddef3a564..84a31831e5b 100644 --- a/crates/storage/Cargo.toml +++ b/crates/storage/Cargo.toml @@ -25,8 +25,7 @@ scale = { package = "parity-scale-codec", version = "2.0", default-features = fa derive_more = { version = "0.99", default-features = false, features = ["from", "display"] } scale-info = { version = "0.5", default-features = false, features = ["derive"], optional = true } cfg-if = "1.0" -array-init = "1.0" -generic-array = "0.14.1" +array-init = { version = "1.0", default-features = false, features = ["const-generics"] } # Workaround: we actually just need criterion as a dev-dependency, but # there is an issue with a doubly included std lib when executing @@ -54,6 +53,7 @@ std = [ "scale-info/std", ] ink-fuzz-tests = ["std"] +ink-unstable = ["std"] [[bench]] name = "bench_lazy" diff --git a/crates/storage/src/collections/mod.rs b/crates/storage/src/collections/mod.rs index 7a4d0b33bad..5956ef1e1ff 100644 --- a/crates/storage/src/collections/mod.rs +++ b/crates/storage/src/collections/mod.rs @@ -22,6 +22,7 @@ pub mod binary_heap; pub mod bitstash; pub mod bitvec; pub mod hashmap; +#[cfg(feature = "ink-unstable")] pub mod smallvec; pub mod stash; pub mod vec; @@ -32,11 +33,14 @@ pub use self::{ bitstash::BitStash, bitvec::Bitvec, hashmap::HashMap, - smallvec::SmallVec, stash::Stash, vec::Vec, }; +#[cfg(feature = "ink-unstable")] +#[doc(inline)] +pub use self::smallvec::SmallVec; + /// Extends the lifetime 'a to the outliving lifetime 'b for the given reference. /// /// # Note diff --git a/crates/storage/src/collections/smallvec/impls.rs b/crates/storage/src/collections/smallvec/impls.rs index c91f2bebbc9..9e0f90a38c2 100644 --- a/crates/storage/src/collections/smallvec/impls.rs +++ b/crates/storage/src/collections/smallvec/impls.rs @@ -16,29 +16,24 @@ use super::{ Iter, SmallVec, }; -use crate::{ - lazy::LazyArrayLength, - traits::PackedLayout, -}; +use crate::traits::PackedLayout; use core::iter::{ Extend, FromIterator, }; -impl Drop for SmallVec +impl Drop for SmallVec where T: PackedLayout, - N: LazyArrayLength, { fn drop(&mut self) { self.clear_cells() } } -impl core::ops::Index for SmallVec +impl core::ops::Index for SmallVec where T: PackedLayout, - N: LazyArrayLength, { type Output = T; @@ -56,10 +51,9 @@ where } } -impl core::ops::IndexMut for SmallVec +impl core::ops::IndexMut for SmallVec where T: PackedLayout, - N: LazyArrayLength, { fn index_mut(&mut self, index: u32) -> &mut Self::Output { let len = self.len(); @@ -75,10 +69,9 @@ where } } -impl<'a, T: 'a, N> IntoIterator for &'a SmallVec +impl<'a, T: 'a, const N: usize> IntoIterator for &'a SmallVec where T: PackedLayout, - N: LazyArrayLength, { type Item = &'a T; type IntoIter = Iter<'a, T, N>; @@ -88,10 +81,9 @@ where } } -impl Extend for SmallVec +impl Extend for SmallVec where T: PackedLayout, - N: LazyArrayLength, { fn extend(&mut self, iter: I) where @@ -103,10 +95,9 @@ where } } -impl FromIterator for SmallVec +impl FromIterator for SmallVec where T: PackedLayout, - N: LazyArrayLength, { fn from_iter(iter: I) -> Self where @@ -118,10 +109,9 @@ where } } -impl core::cmp::PartialEq for SmallVec +impl core::cmp::PartialEq for SmallVec where T: PartialEq + PackedLayout, - N: LazyArrayLength, { fn eq(&self, other: &Self) -> bool { if self.len() != other.len() { @@ -131,9 +121,4 @@ where } } -impl core::cmp::Eq for SmallVec -where - T: Eq + PackedLayout, - N: LazyArrayLength, -{ -} +impl core::cmp::Eq for SmallVec where T: Eq + PackedLayout {} diff --git a/crates/storage/src/collections/smallvec/iter.rs b/crates/storage/src/collections/smallvec/iter.rs index 55d24047be8..3ae9c4d38be 100644 --- a/crates/storage/src/collections/smallvec/iter.rs +++ b/crates/storage/src/collections/smallvec/iter.rs @@ -15,16 +15,14 @@ use super::SmallVec; use crate::{ collections::extend_lifetime, - lazy::LazyArrayLength, traits::PackedLayout, }; /// An iterator over shared references to the elements of a small storage vector. #[derive(Debug, Clone, Copy)] -pub struct Iter<'a, T, N> +pub struct Iter<'a, T, const N: usize> where T: PackedLayout, - N: LazyArrayLength, { /// The storage vector to iterate over. vec: &'a SmallVec, @@ -34,10 +32,9 @@ where end: u32, } -impl<'a, T, N> Iter<'a, T, N> +impl<'a, T, const N: usize> Iter<'a, T, N> where T: PackedLayout, - N: LazyArrayLength, { /// Creates a new iterator for the given storage vector. pub(crate) fn new(vec: &'a SmallVec) -> Self { @@ -54,10 +51,9 @@ where } } -impl<'a, T, N> Iterator for Iter<'a, T, N> +impl<'a, T, const N: usize> Iterator for Iter<'a, T, N> where T: PackedLayout, - N: LazyArrayLength, { type Item = &'a T; @@ -86,17 +82,11 @@ where } } -impl<'a, T, N> ExactSizeIterator for Iter<'a, T, N> -where - T: PackedLayout, - N: LazyArrayLength, -{ -} +impl<'a, T, const N: usize> ExactSizeIterator for Iter<'a, T, N> where T: PackedLayout {} -impl<'a, T, N> DoubleEndedIterator for Iter<'a, T, N> +impl<'a, T, const N: usize> DoubleEndedIterator for Iter<'a, T, N> where T: PackedLayout, - N: LazyArrayLength, { fn next_back(&mut self) -> Option { ::nth_back(self, 0) @@ -118,10 +108,9 @@ where /// An iterator over exclusive references to the elements of a small storage vector. #[derive(Debug)] -pub struct IterMut<'a, T, N> +pub struct IterMut<'a, T, const N: usize> where T: PackedLayout, - N: LazyArrayLength, { /// The storage vector to iterate over. vec: &'a mut SmallVec, @@ -131,10 +120,9 @@ where end: u32, } -impl<'a, T, N> IterMut<'a, T, N> +impl<'a, T, const N: usize> IterMut<'a, T, N> where T: PackedLayout, - N: LazyArrayLength, { /// Creates a new iterator for the given storage vector. pub(crate) fn new(vec: &'a mut SmallVec) -> Self { @@ -152,10 +140,9 @@ where } } -impl<'a, T, N> IterMut<'a, T, N> +impl<'a, T, const N: usize> IterMut<'a, T, N> where T: PackedLayout, - N: LazyArrayLength, { fn get_mut<'b>(&'b mut self, at: u32) -> Option<&'a mut T> { self.vec.get_mut(at).map(|value| { @@ -171,10 +158,9 @@ where } } -impl<'a, T, N> Iterator for IterMut<'a, T, N> +impl<'a, T, const N: usize> Iterator for IterMut<'a, T, N> where T: PackedLayout, - N: LazyArrayLength, { type Item = &'a mut T; @@ -203,17 +189,11 @@ where } } -impl<'a, T, N> ExactSizeIterator for IterMut<'a, T, N> -where - T: PackedLayout, - N: LazyArrayLength, -{ -} +impl<'a, T, const N: usize> ExactSizeIterator for IterMut<'a, T, N> where T: PackedLayout {} -impl<'a, T, N> DoubleEndedIterator for IterMut<'a, T, N> +impl<'a, T, const N: usize> DoubleEndedIterator for IterMut<'a, T, N> where T: PackedLayout, - N: LazyArrayLength, { fn next_back(&mut self) -> Option { ::nth_back(self, 0) diff --git a/crates/storage/src/collections/smallvec/mod.rs b/crates/storage/src/collections/smallvec/mod.rs index e8078767850..f66a01939b5 100644 --- a/crates/storage/src/collections/smallvec/mod.rs +++ b/crates/storage/src/collections/smallvec/mod.rs @@ -34,7 +34,6 @@ use crate::{ lazy::{ Lazy, LazyArray, - LazyArrayLength, }, traits::PackedLayout, }; @@ -55,10 +54,9 @@ type Index = u32; /// `Vec` due to the internal differences. /// - Allows to store up to N elements. #[derive(Debug)] -pub struct SmallVec +pub struct SmallVec where T: PackedLayout, - N: LazyArrayLength, { /// The current length of the small vector. len: Lazy, @@ -66,20 +64,18 @@ where elems: LazyArray, } -impl Default for SmallVec +impl Default for SmallVec where T: PackedLayout, - N: LazyArrayLength, { fn default() -> Self { Self::new() } } -impl SmallVec +impl SmallVec where T: PackedLayout, - N: LazyArrayLength, { /// Clears the underlying storage cells of the storage vector. /// @@ -103,10 +99,9 @@ where } } -impl SmallVec +impl SmallVec where T: PackedLayout, - N: LazyArrayLength, { /// Creates a new empty vector. pub fn new() -> Self { @@ -135,10 +130,9 @@ where } } -impl SmallVec +impl SmallVec where T: PackedLayout, - N: LazyArrayLength, { /// Returns an iterator yielding shared references to all elements. /// @@ -196,10 +190,9 @@ where } } -impl SmallVec +impl SmallVec where T: PackedLayout, - N: LazyArrayLength, { /// Appends an element to the back of the vector. pub fn push(&mut self, value: T) { @@ -213,10 +206,9 @@ where } } -impl SmallVec +impl SmallVec where T: PackedLayout, - N: LazyArrayLength, { /// Pops the last element from the vector and returns it. // diff --git a/crates/storage/src/collections/smallvec/storage.rs b/crates/storage/src/collections/smallvec/storage.rs index 38b59766c77..510ec1b7252 100644 --- a/crates/storage/src/collections/smallvec/storage.rs +++ b/crates/storage/src/collections/smallvec/storage.rs @@ -13,22 +13,17 @@ // limitations under the License. use super::SmallVec; -use crate::{ - lazy::LazyArrayLength, - traits::{ - KeyPtr, - PackedLayout, - SpreadLayout, - }, +use crate::traits::{ + KeyPtr, + PackedLayout, + SpreadLayout, }; -use generic_array::typenum::Unsigned; #[cfg(feature = "std")] const _: () = { - use crate::{ - lazy::LazyArray, - traits::StorageLayout, - }; + #[cfg(feature = "ink-unstable")] + use crate::lazy::LazyArray; + use crate::traits::StorageLayout; use ink_metadata::layout::{ FieldLayout, Layout, @@ -36,10 +31,9 @@ const _: () = { }; use scale_info::TypeInfo; - impl StorageLayout for SmallVec + impl StorageLayout for SmallVec where T: PackedLayout + TypeInfo + 'static, - N: LazyArrayLength, { fn layout(key_ptr: &mut KeyPtr) -> Layout { Layout::Struct(StructLayout::new(vec![ @@ -53,12 +47,11 @@ const _: () = { } }; -impl SpreadLayout for SmallVec +impl SpreadLayout for SmallVec where T: PackedLayout, - N: LazyArrayLength, { - const FOOTPRINT: u64 = 1 + ::U64; + const FOOTPRINT: u64 = 1 + N as u64; fn pull_spread(ptr: &mut KeyPtr) -> Self { Self { diff --git a/crates/storage/src/collections/smallvec/tests.rs b/crates/storage/src/collections/smallvec/tests.rs index 300152ad84e..a99079e5149 100644 --- a/crates/storage/src/collections/smallvec/tests.rs +++ b/crates/storage/src/collections/smallvec/tests.rs @@ -20,17 +20,16 @@ use crate::{ }, Lazy, }; -use generic_array::typenum::*; use ink_primitives::Key; #[test] fn new_vec_works() { - let vec = >::new(); + let vec = >::new(); assert!(vec.is_empty()); assert_eq!(vec.len(), 0); assert_eq!(vec.get(0), None); assert!(vec.iter().next().is_none()); - let default = as Default>::default(); + let default = as Default>::default(); assert!(default.is_empty()); assert_eq!(default.len(), 0); assert_eq!(vec.get(0), None); @@ -40,7 +39,7 @@ fn new_vec_works() { #[test] fn from_iterator_works() { let some_primes = [b'A', b'B', b'C', b'D']; - assert_eq!(some_primes.iter().copied().collect::>(), { + assert_eq!(some_primes.iter().copied().collect::>(), { let mut vec = SmallVec::new(); for prime in &some_primes { vec.push(*prime) @@ -53,20 +52,20 @@ fn from_iterator_works() { #[should_panic] fn from_iterator_too_many() { let some_primes = [b'A', b'B', b'C', b'D', b'E']; - let _ = some_primes.iter().copied().collect::>(); + let _ = some_primes.iter().copied().collect::>(); } #[test] fn from_empty_iterator_works() { assert_eq!( - [].iter().copied().collect::>(), + [].iter().copied().collect::>(), SmallVec::new(), ); } #[test] fn first_last_of_empty() { - let mut vec = >::new(); + let mut vec = >::new(); assert_eq!(vec.first(), None); assert_eq!(vec.first_mut(), None); assert_eq!(vec.last(), None); @@ -75,14 +74,14 @@ fn first_last_of_empty() { #[test] fn pop_on_empty_works() { - let mut vec = >::new(); + let mut vec = >::new(); assert_eq!(vec.pop(), None); } #[test] fn push_pop_first_last_works() { /// Asserts conditions are met for the given storage vector. - fn assert_vec(vec: &SmallVec, len: u32, first: F, last: L) + fn assert_vec(vec: &SmallVec, len: u32, first: F, last: L) where F: Into>, L: Into>, @@ -127,18 +126,18 @@ fn push_beyond_limits_fails() { let mut vec = [b'A', b'B', b'C', b'D'] .iter() .copied() - .collect::>(); + .collect::>(); vec.push(b'E'); } /// Creates a storage vector from the given slice. -fn vec_from_slice(slice: &[u8]) -> SmallVec { - slice.iter().copied().collect::>() +fn vec_from_slice(slice: &[u8]) -> SmallVec { + slice.iter().copied().collect::>() } /// Asserts that the the given ordered storage vector elements are equal to the /// ordered elements of the given slice. -fn assert_eq_slice(vec: &SmallVec, slice: &[u8]) { +fn assert_eq_slice(vec: &SmallVec, slice: &[u8]) { assert_eq!(vec.len() as usize, slice.len()); let vec_copy = vec.iter().copied().collect::>(); assert_eq!(vec_copy.as_slice(), slice); @@ -371,7 +370,7 @@ fn spread_layout_push_pull_works() -> ink_env::Result<()> { // Load the pushed storage vector into another instance and check that // both instances are equal: let vec2 = - as SpreadLayout>::pull_spread(&mut KeyPtr::from(root_key)); + as SpreadLayout>::pull_spread(&mut KeyPtr::from(root_key)); assert_eq!(vec1, vec2); Ok(()) }) @@ -392,7 +391,7 @@ fn spread_layout_clear_works() { // vector's length property cannot read a value: SpreadLayout::clear_spread(&vec1, &mut KeyPtr::from(root_key)); let _ = - as SpreadLayout>::pull_spread(&mut KeyPtr::from(root_key)); + as SpreadLayout>::pull_spread(&mut KeyPtr::from(root_key)); Ok(()) }) .unwrap() @@ -405,7 +404,7 @@ fn storage_is_cleared_completely_after_pull_lazy() { let root_key = Key::from([0x42; 32]); let lazy_vec = Lazy::new(vec_from_slice(&[b'a', b'b', b'c', b'd'])); SpreadLayout::push_spread(&lazy_vec, &mut KeyPtr::from(root_key)); - let pulled_vec = > as SpreadLayout>::pull_spread( + let pulled_vec = > as SpreadLayout>::pull_spread( &mut KeyPtr::from(root_key), ); @@ -438,7 +437,7 @@ fn drop_works() { let setup_result = std::panic::catch_unwind(|| { let vec = vec_from_slice(&[b'a', b'b', b'c', b'd']); SpreadLayout::push_spread(&vec, &mut KeyPtr::from(root_key)); - let _ = as SpreadLayout>::pull_spread(&mut KeyPtr::from( + let _ = as SpreadLayout>::pull_spread(&mut KeyPtr::from( root_key, )); // vec is dropped which should clear the cells @@ -456,7 +455,7 @@ fn drop_works() { assert_eq!(used_cells, 0); let _ = - as SpreadLayout>::pull_spread(&mut KeyPtr::from(root_key)); + as SpreadLayout>::pull_spread(&mut KeyPtr::from(root_key)); Ok(()) }) .unwrap() diff --git a/crates/storage/src/lazy/cache_cell.rs b/crates/storage/src/lazy/cache_cell.rs index cea7d623586..daa23206a8d 100644 --- a/crates/storage/src/lazy/cache_cell.rs +++ b/crates/storage/src/lazy/cache_cell.rs @@ -38,6 +38,7 @@ impl CacheCell { } /// Returns the inner value. + #[allow(dead_code)] pub fn into_inner(self) -> T { self.inner.into_inner() } diff --git a/crates/storage/src/lazy/lazy_array.rs b/crates/storage/src/lazy/lazy_array.rs index 3437296f453..f168bea549a 100644 --- a/crates/storage/src/lazy/lazy_array.rs +++ b/crates/storage/src/lazy/lazy_array.rs @@ -31,37 +31,11 @@ use core::{ mem, ptr::NonNull, }; -use generic_array::{ - typenum::{ - UInt, - UTerm, - Unsigned, - B0, - B1, - }, - ArrayLength, - GenericArray, -}; use ink_primitives::Key; /// The index type used in the lazy storage chunk. pub type Index = u32; -/// Utility trait for helping with lazy array construction. -pub trait LazyArrayLength: - ArrayLength>>> + Unsigned -{ -} -impl LazyArrayLength for UTerm {} -impl>>>> LazyArrayLength - for UInt -{ -} -impl>>>> LazyArrayLength - for UInt -{ -} - /// A lazy storage array that spans over N storage cells. /// /// Storage data structure to emulate storage arrays: `[T; N]`. @@ -75,10 +49,7 @@ impl>>>> LazyArrayLength /// This is mainly used as low-level storage primitives by other high-level /// storage primitives in order to manage the contract storage for a whole /// chunk of storage cells. -pub struct LazyArray -where - N: LazyArrayLength, -{ +pub struct LazyArray { /// The offset key for the N cells. /// /// If the lazy chunk has been initialized during contract initialization @@ -104,13 +75,12 @@ const _: () = { }; use scale_info::TypeInfo; - impl StorageLayout for LazyArray + impl StorageLayout for LazyArray where T: TypeInfo + 'static, - N: LazyArrayLength, { fn layout(key_ptr: &mut KeyPtr) -> Layout { - let capacity = ::U32; + let capacity = N as u32; Layout::Array(ArrayLayout::new( LayoutKey::from(key_ptr.advance_by(capacity as u64)), capacity, @@ -123,15 +93,13 @@ const _: () = { } }; -struct DebugEntryArray<'a, T, N>(&'a EntryArray) +struct DebugEntryArray<'a, T, const N: usize>(&'a EntryArray) where - T: Debug, - N: LazyArrayLength; + T: Debug; -impl<'a, T, N> Debug for DebugEntryArray<'a, T, N> +impl<'a, T, const N: usize> Debug for DebugEntryArray<'a, T, N> where T: Debug, - N: LazyArrayLength, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_map() @@ -145,10 +113,9 @@ where } } -impl Debug for LazyArray +impl Debug for LazyArray where T: Debug, - N: LazyArrayLength, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("LazyArray") @@ -160,8 +127,7 @@ where #[test] fn debug_impl_works() { - use generic_array::typenum::U4; - let mut larray = >::new(); + let mut larray = >::new(); // Empty imap. assert_eq!( format!("{:?}", &larray), @@ -194,21 +160,15 @@ fn debug_impl_works() { } /// Returns the capacity for an array with the given array length. -fn array_capacity() -> u32 -where - N: LazyArrayLength, -{ - ::U32 +fn array_capacity() -> u32 { + N as u32 } /// The underlying array cache for the [`LazyArray`]. #[derive(Debug)] -pub struct EntryArray -where - N: LazyArrayLength, -{ +pub struct EntryArray { /// The cache entries of the entry array. - entries: GenericArray>>, N>, + entries: [CacheCell>>; N], } #[derive(Debug)] @@ -217,10 +177,7 @@ pub struct EntriesIter<'a, T> { } impl<'a, T> EntriesIter<'a, T> { - pub fn new(entry_array: &'a EntryArray) -> Self - where - N: LazyArrayLength, - { + pub fn new(entry_array: &'a EntryArray) -> Self { Self { iter: entry_array.entries.iter(), } @@ -254,31 +211,22 @@ impl<'a, T> DoubleEndedIterator for EntriesIter<'a, T> { impl<'a, T> ExactSizeIterator for EntriesIter<'a, T> {} -impl EntryArray -where - N: LazyArrayLength, -{ +impl EntryArray { /// Creates a new entry array cache. pub fn new() -> Self { Self { - entries: Default::default(), + entries: array_init::array_init(|_| Default::default()), } } } -impl Default for EntryArray -where - N: LazyArrayLength, -{ +impl Default for EntryArray { fn default() -> Self { Self::new() } } -impl EntryArray -where - N: LazyArrayLength, -{ +impl EntryArray { /// Returns the constant capacity of the lazy array. #[inline] pub fn capacity() -> u32 { @@ -289,7 +237,7 @@ where /// returns the old value if any. fn put(&self, at: Index, new_value: Option) -> Option { mem::replace( - unsafe { self.entries.as_slice()[at as usize].get_ptr().as_mut() }, + unsafe { self.entries[at as usize].get_ptr().as_mut() }, Some(StorageEntry::new(new_value, EntryState::Mutated)), ) .map(StorageEntry::into_value) @@ -325,10 +273,9 @@ where } } -impl LazyArray +impl LazyArray where T: PackedLayout, - N: LazyArrayLength, { /// Clears the underlying storage of the entry at the given index. /// @@ -356,19 +303,13 @@ where } } -impl Default for LazyArray -where - N: LazyArrayLength, -{ +impl Default for LazyArray { fn default() -> Self { Self::new() } } -impl LazyArray -where - N: LazyArrayLength, -{ +impl LazyArray { /// Creates a new empty lazy array. /// /// # Note @@ -428,12 +369,11 @@ where } } -impl SpreadLayout for LazyArray +impl SpreadLayout for LazyArray where T: PackedLayout, - N: LazyArrayLength, { - const FOOTPRINT: u64 = ::U64; + const FOOTPRINT: u64 = N as u64; fn pull_spread(ptr: &mut KeyPtr) -> Self { Self::lazy(*ExtKeyPtr::next_for::(ptr)) @@ -458,10 +398,7 @@ where } } -impl LazyArray -where - N: LazyArrayLength, -{ +impl LazyArray { /// Returns the offset key for the given index if not out of bounds. pub fn key_at(&self, at: Index) -> Option { if at >= self.capacity() { @@ -471,10 +408,9 @@ where } } -impl LazyArray +impl LazyArray where T: PackedLayout, - N: LazyArrayLength, { /// Loads the entry at the given index. /// @@ -604,22 +540,18 @@ mod tests { }, Index, LazyArray, - LazyArrayLength, }; use crate::traits::{ KeyPtr, SpreadLayout, }; - use generic_array::typenum::U4; use ink_primitives::Key; /// Asserts that the cached entries of the given `imap` is equal to the `expected` slice. - fn assert_cached_entries( + fn assert_cached_entries( larray: &LazyArray, expected: &[(Index, StorageEntry)], - ) where - N: LazyArrayLength, - { + ) { let mut len = 0; for (given, expected) in larray .cached_entries() @@ -641,7 +573,7 @@ mod tests { #[test] fn new_works() { - let larray = >::new(); + let larray = >::new(); // Key must be none. assert_eq!(larray.key(), None); assert_eq!(larray.key_at(0), None); @@ -649,7 +581,7 @@ mod tests { // Cached elements must be empty. assert_cached_entries(&larray, &[]); // Same as default: - let default_larray = >::default(); + let default_larray = >::default(); assert_eq!(default_larray.key(), larray.key()); assert_eq!(default_larray.key_at(0), larray.key_at(0)); assert_eq!(larray.capacity(), 4); @@ -659,7 +591,7 @@ mod tests { #[test] fn lazy_works() { let key = Key::from([0x42; 32]); - let larray = >::lazy(key); + let larray = >::lazy(key); // Key must be Some. assert_eq!(larray.key(), Some(&key)); assert_eq!(larray.key_at(0), Some(key)); @@ -671,7 +603,7 @@ mod tests { #[test] fn get_works() { - let mut larray = >::new(); + let mut larray = >::new(); let nothing_changed = &[ (0, StorageEntry::new(None, EntryState::Preserved)), (1, StorageEntry::new(Some(b'B'), EntryState::Mutated)), @@ -701,13 +633,13 @@ mod tests { #[test] #[should_panic(expected = "index is out of bounds")] fn get_out_of_bounds_works() { - let larray = >::new(); + let larray = >::new(); let _ = larray.get(4); } #[test] fn put_get_works() { - let mut larray = >::new(); + let mut larray = >::new(); // Assert that the array cache is empty at first. assert_cached_entries(&larray, &[]); // Put none values. @@ -750,13 +682,13 @@ mod tests { #[test] #[should_panic(expected = "index is out of bounds")] fn put_get_out_of_bounds_works() { - let mut larray = >::new(); + let mut larray = >::new(); let _ = larray.put_get(4, Some(b'A')); } #[test] fn put_works() { - let mut larray = >::new(); + let mut larray = >::new(); // Put some values. larray.put(0, None); larray.put(1, Some(b'B')); @@ -792,13 +724,13 @@ mod tests { #[test] #[should_panic(expected = "index out of bounds: the len is 4 but the index is 4")] fn put_out_of_bounds_works() { - let mut larray = >::new(); + let mut larray = >::new(); larray.put(4, Some(b'A')); } #[test] fn swap_works() { - let mut larray = >::new(); + let mut larray = >::new(); let nothing_changed = &[ (0, StorageEntry::new(Some(b'A'), EntryState::Mutated)), (1, StorageEntry::new(Some(b'B'), EntryState::Mutated)), @@ -847,21 +779,21 @@ mod tests { #[test] #[should_panic(expected = "b is out of bounds")] fn swap_rhs_out_of_bounds() { - let mut larray = >::new(); + let mut larray = >::new(); larray.swap(0, 4); } #[test] #[should_panic(expected = "a is out of bounds")] fn swap_both_out_of_bounds() { - let mut larray = >::new(); + let mut larray = >::new(); larray.swap(4, 4); } #[test] fn spread_layout_works() -> ink_env::Result<()> { ink_env::test::run_test::(|_| { - let mut larray = >::new(); + let mut larray = >::new(); let nothing_changed = &[ (0, StorageEntry::new(Some(b'A'), EntryState::Mutated)), (1, StorageEntry::new(Some(b'B'), EntryState::Mutated)), @@ -879,7 +811,7 @@ mod tests { // Then: Compare both instances to be equal. let root_key = Key::from([0x42; 32]); SpreadLayout::push_spread(&larray, &mut KeyPtr::from(root_key)); - let larray2 = as SpreadLayout>::pull_spread( + let larray2 = as SpreadLayout>::pull_spread( &mut KeyPtr::from(root_key), ); assert_cached_entries(&larray2, &[]); @@ -908,7 +840,7 @@ mod tests { larray2.clear_packed_at(1); larray2.clear_packed_at(2); // Not really needed here. larray2.clear_packed_at(3); // Not really needed here. - let larray3 = as SpreadLayout>::pull_spread( + let larray3 = as SpreadLayout>::pull_spread( &mut KeyPtr::from(root_key), ); assert_cached_entries(&larray3, &[]); diff --git a/crates/storage/src/lazy/mod.rs b/crates/storage/src/lazy/mod.rs index 30bfb90136a..be22d26f6d0 100644 --- a/crates/storage/src/lazy/mod.rs +++ b/crates/storage/src/lazy/mod.rs @@ -28,10 +28,14 @@ pub mod lazy_hmap; mod cache_cell; mod entry; +#[cfg(feature = "ink-unstable")] mod lazy_array; mod lazy_cell; mod lazy_imap; +#[cfg(feature = "ink-unstable")] +#[doc(inline)] +pub use self::lazy_array::LazyArray; use self::{ cache_cell::CacheCell, entry::{ @@ -41,10 +45,6 @@ use self::{ }; #[doc(inline)] pub use self::{ - lazy_array::{ - LazyArray, - LazyArrayLength, - }, lazy_cell::LazyCell, lazy_hmap::LazyHashMap, lazy_imap::LazyIndexMap,