diff --git a/crates/storage/src/collections/smallvec/impls.rs b/crates/storage/src/collections/smallvec/impls.rs index 45de5f4af42..87280852e61 100644 --- a/crates/storage/src/collections/smallvec/impls.rs +++ b/crates/storage/src/collections/smallvec/impls.rs @@ -16,9 +16,7 @@ use super::{ Iter, SmallVec, }; -use crate::{ - traits::PackedLayout, -}; +use crate::traits::PackedLayout; use core::iter::{ Extend, FromIterator, @@ -123,8 +121,4 @@ where } } -impl core::cmp::Eq for SmallVec -where - T: Eq + PackedLayout, -{ -} +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 05149b4ae30..12fb25ce5b5 100644 --- a/crates/storage/src/collections/smallvec/iter.rs +++ b/crates/storage/src/collections/smallvec/iter.rs @@ -82,11 +82,7 @@ where } } -impl<'a, T, const N: usize> ExactSizeIterator for Iter<'a, T, N> -where - T: PackedLayout, -{ -} +impl<'a, T, const N: usize> ExactSizeIterator for Iter<'a, T, N> where T: PackedLayout {} impl<'a, T, const N: usize> DoubleEndedIterator for Iter<'a, T, N> where @@ -193,11 +189,7 @@ where } } -impl<'a, T, const N: usize> ExactSizeIterator for IterMut<'a, T, N> -where - T: PackedLayout, -{ -} +impl<'a, T, const N: usize> ExactSizeIterator for IterMut<'a, T, N> where T: PackedLayout {} impl<'a, T, const N: usize> DoubleEndedIterator for IterMut<'a, T, N> where diff --git a/crates/storage/src/collections/smallvec/storage.rs b/crates/storage/src/collections/smallvec/storage.rs index 94817253e76..7b14149f880 100644 --- a/crates/storage/src/collections/smallvec/storage.rs +++ b/crates/storage/src/collections/smallvec/storage.rs @@ -13,12 +13,10 @@ // limitations under the License. use super::SmallVec; -use crate::{ - traits::{ - KeyPtr, - PackedLayout, - SpreadLayout, - }, +use crate::traits::{ + KeyPtr, + PackedLayout, + SpreadLayout, }; #[cfg(feature = "std")] diff --git a/crates/storage/src/lazy/lazy_array.rs b/crates/storage/src/lazy/lazy_array.rs index 3464300dfa5..cc1206b97ae 100644 --- a/crates/storage/src/lazy/lazy_array.rs +++ b/crates/storage/src/lazy/lazy_array.rs @@ -26,8 +26,10 @@ use crate::traits::{ SpreadLayout, }; use core::{ + convert::TryInto, fmt, fmt::Debug, + iter, mem, ptr::NonNull, }; @@ -49,8 +51,7 @@ pub type Index = u32; /// 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 -{ +pub struct LazyArray { /// The offset key for the N cells. /// /// If the lazy chunk has been initialized during contract initialization @@ -161,15 +162,13 @@ fn debug_impl_works() { } /// Returns the capacity for an array with the given array length. -fn array_capacity() -> u32 -{ +fn array_capacity() -> u32 { N as u32 } /// The underlying array cache for the [`LazyArray`]. #[derive(Debug)] -pub struct EntryArray -{ +pub struct EntryArray { /// The cache entries of the entry array. entries: [CacheCell>>; N], } @@ -180,8 +179,7 @@ pub struct EntriesIter<'a, T> { } impl<'a, T> EntriesIter<'a, T> { - pub fn new(entry_array: &'a EntryArray) -> Self - { + pub fn new(entry_array: &'a EntryArray) -> Self { Self { iter: entry_array.entries.iter(), } @@ -215,25 +213,28 @@ impl<'a, T> DoubleEndedIterator for EntriesIter<'a, T> { impl<'a, T> ExactSizeIterator for EntriesIter<'a, T> {} -impl EntryArray -{ +impl EntryArray { /// Creates a new entry array cache. pub fn new() -> Self { - Self { - entries: [(); N].map(|_|Default::default()) - } + let entries = iter::repeat_with(|| Default::default()) + .take(N) + .collect::>>>>() + .try_into(); + let entries = match entries { + Ok(entries) => entries, + Err(_) => unreachable!("try_into must work"), + }; + Self { entries } } } -impl Default for EntryArray -{ +impl Default for EntryArray { fn default() -> Self { Self::new() } } -impl EntryArray -{ +impl EntryArray { /// Returns the constant capacity of the lazy array. #[inline] pub fn capacity() -> u32 { @@ -244,7 +245,7 @@ impl EntryArray /// 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) @@ -310,15 +311,13 @@ where } } -impl Default for LazyArray -{ +impl Default for LazyArray { fn default() -> Self { Self::new() } } -impl LazyArray -{ +impl LazyArray { /// Creates a new empty lazy array. /// /// # Note @@ -407,8 +406,7 @@ where } } -impl LazyArray -{ +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() { diff --git a/crates/storage/src/lazy/mod.rs b/crates/storage/src/lazy/mod.rs index bb3368efd80..aaa1af85951 100644 --- a/crates/storage/src/lazy/mod.rs +++ b/crates/storage/src/lazy/mod.rs @@ -41,9 +41,7 @@ use self::{ }; #[doc(inline)] pub use self::{ - lazy_array::{ - LazyArray, - }, + lazy_array::LazyArray, lazy_cell::LazyCell, lazy_hmap::LazyHashMap, lazy_imap::LazyIndexMap, diff --git a/crates/storage/src/lib.rs b/crates/storage/src/lib.rs index 91357473d98..84807314e6f 100644 --- a/crates/storage/src/lib.rs +++ b/crates/storage/src/lib.rs @@ -20,8 +20,6 @@ //! FFI to interface with SRML contracts and a primitive blockchain //! emulator for simple off-chain testing. -#![feature(array_map)] -#![feature(array_methods)] #![feature(min_const_generics)] #![cfg_attr(not(feature = "std"), no_std)]