Skip to content

Commit

Permalink
Fmt and get rid of feature flags
Browse files Browse the repository at this point in the history
  • Loading branch information
cmichi committed Nov 26, 2020
1 parent 26bd567 commit b58062d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 53 deletions.
10 changes: 2 additions & 8 deletions crates/storage/src/collections/smallvec/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ use super::{
Iter,
SmallVec,
};
use crate::{
traits::PackedLayout,
};
use crate::traits::PackedLayout;
use core::iter::{
Extend,
FromIterator,
Expand Down Expand Up @@ -123,8 +121,4 @@ where
}
}

impl<T, const N: usize> core::cmp::Eq for SmallVec<T, N>
where
T: Eq + PackedLayout,
{
}
impl<T, const N: usize> core::cmp::Eq for SmallVec<T, N> where T: Eq + PackedLayout {}
12 changes: 2 additions & 10 deletions crates/storage/src/collections/smallvec/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions crates/storage/src/collections/smallvec/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
46 changes: 22 additions & 24 deletions crates/storage/src/lazy/lazy_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ use crate::traits::{
SpreadLayout,
};
use core::{
convert::TryInto,
fmt,
fmt::Debug,
iter,
mem,
ptr::NonNull,
};
Expand All @@ -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<T, const N: usize>
{
pub struct LazyArray<T, const N: usize> {
/// The offset key for the N cells.
///
/// If the lazy chunk has been initialized during contract initialization
Expand Down Expand Up @@ -161,15 +162,13 @@ fn debug_impl_works() {
}

/// Returns the capacity for an array with the given array length.
fn array_capacity<T, const N: usize>() -> u32
{
fn array_capacity<T, const N: usize>() -> u32 {
N as u32
}

/// The underlying array cache for the [`LazyArray`].
#[derive(Debug)]
pub struct EntryArray<T, const N: usize>
{
pub struct EntryArray<T, const N: usize> {
/// The cache entries of the entry array.
entries: [CacheCell<Option<StorageEntry<T>>>; N],
}
Expand All @@ -180,8 +179,7 @@ pub struct EntriesIter<'a, T> {
}

impl<'a, T> EntriesIter<'a, T> {
pub fn new<const N: usize>(entry_array: &'a EntryArray<T, N>) -> Self
{
pub fn new<const N: usize>(entry_array: &'a EntryArray<T, N>) -> Self {
Self {
iter: entry_array.entries.iter(),
}
Expand Down Expand Up @@ -215,25 +213,28 @@ impl<'a, T> DoubleEndedIterator for EntriesIter<'a, T> {

impl<'a, T> ExactSizeIterator for EntriesIter<'a, T> {}

impl<T, const N: usize> EntryArray<T, N>
{
impl<T, const N: usize> EntryArray<T, N> {
/// 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::<Vec<CacheCell<Option<StorageEntry<T>>>>>()
.try_into();
let entries = match entries {
Ok(entries) => entries,
Err(_) => unreachable!("try_into must work"),
};
Self { entries }
}
}

impl<T, const N: usize> Default for EntryArray<T, N>
{
impl<T, const N: usize> Default for EntryArray<T, N> {
fn default() -> Self {
Self::new()
}
}

impl<T, const N: usize> EntryArray<T, N>
{
impl<T, const N: usize> EntryArray<T, N> {
/// Returns the constant capacity of the lazy array.
#[inline]
pub fn capacity() -> u32 {
Expand All @@ -244,7 +245,7 @@ impl<T, const N: usize> EntryArray<T, N>
/// returns the old value if any.
fn put(&self, at: Index, new_value: Option<T>) -> Option<T> {
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)
Expand Down Expand Up @@ -310,15 +311,13 @@ where
}
}

impl<T, const N: usize> Default for LazyArray<T, N>
{
impl<T, const N: usize> Default for LazyArray<T, N> {
fn default() -> Self {
Self::new()
}
}

impl<T, const N: usize> LazyArray<T, N>
{
impl<T, const N: usize> LazyArray<T, N> {
/// Creates a new empty lazy array.
///
/// # Note
Expand Down Expand Up @@ -407,8 +406,7 @@ where
}
}

impl<T, const N: usize> LazyArray<T, N>
{
impl<T, const N: usize> LazyArray<T, N> {
/// Returns the offset key for the given index if not out of bounds.
pub fn key_at(&self, at: Index) -> Option<Key> {
if at >= self.capacity() {
Expand Down
4 changes: 1 addition & 3 deletions crates/storage/src/lazy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions crates/storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit b58062d

Please sign in to comment.