Unverified Commit 76c10bd1 authored by Hero Bird's avatar Hero Bird Committed by GitHub

Use ink_prelude crate in the rest of ink! (#285)

* [*] use ink_prelude crate in the rest of ink!

# Conflicts:
#	core/Cargo.toml
#	core/src/storage/flush.rs

* [core] fix usage of ink_prelude in buffer_arena

* [core] apply rustfmt
parent 19fe1917
Pipeline #70484 passed with stages
in 7 minutes and 55 seconds
......@@ -17,7 +17,8 @@ include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"]
[dependencies]
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"] }
derive_more = { version = "0.99.2", default-features = false, features = ["from"] }
ink_abi_derive = { version = "0.1.0", path = "derive", default-features = false, optional = true }
ink_abi_derive = { path = "derive", default-features = false, optional = true }
ink_prelude = { path = "../prelude/", default-features = false }
type-metadata = { git = "https://github.com/type-metadata/type-metadata.git", default-features = false, features = ["derive"] }
[dev-dependencies]
......@@ -30,6 +31,7 @@ default = [
]
std = [
"ink_abi_derive/std",
"ink_prelude/std",
"serde/std",
"type-metadata/std",
]
......
......@@ -18,7 +18,8 @@ include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"]
ink_abi = { path = "../abi/", default-features = false, features = ["derive"], optional = true }
ink_alloc = { path = "../alloc/", default-features = false }
ink_utils = { path = "../utils/" }
ink_core_derive = { version = "0.1.0", path = "derive", default-features = false }
ink_core_derive = { path = "derive", default-features = false }
ink_prelude = { path = "../prelude/", default-features = false }
scale = { package = "parity-scale-codec", version = "1.1", default-features = false, features = ["derive", "full"] }
type-metadata = { git = "https://github.com/type-metadata/type-metadata.git", default-features = false, features = ["derive"], optional = true }
......@@ -34,6 +35,7 @@ test-env = [
std = [
"ink_abi/std",
"ink_alloc/std",
"ink_prelude/std",
"scale/std",
"type-metadata/std",
]
......
......@@ -28,9 +28,9 @@ use crate::{
CreateError,
EnvStorage as _,
},
memory::vec::Vec,
storage::Key,
};
use ink_prelude::vec::Vec;
/// Stores the given value under the specified key in the contract storage.
///
......
......@@ -16,18 +16,16 @@ use core::marker::PhantomData;
use scale::Decode;
use crate::{
env::{
self,
CallError,
CreateError,
Env,
EnvTypes,
},
memory::{
vec,
vec::Vec,
},
use crate::env::{
self,
CallError,
CreateError,
Env,
EnvTypes,
};
use ink_prelude::{
vec,
vec::Vec,
};
/// Consists of the input data to a call.
......
......@@ -28,9 +28,9 @@ use crate::{
EnvStorage,
EnvTypes,
},
memory::vec::Vec,
storage::Key,
};
use ink_prelude::vec::Vec;
/// Load the contents of the scratch buffer
fn read_scratch_buffer() -> Vec<u8> {
......
......@@ -29,12 +29,12 @@ use crate::{
CallError,
EnvTypes,
},
memory::collections::hash_map::{
Entry,
HashMap,
},
storage::Key,
};
use ink_prelude::collections::hash_map::{
Entry,
HashMap,
};
/// A wrapper for the generic bytearray used for data in contract events.
#[derive(Debug, Clone, PartialEq, Eq)]
......
......@@ -17,10 +17,8 @@ use scale::{
Decode,
};
use crate::{
memory::vec::Vec,
storage::Key,
};
use crate::storage::Key;
use ink_prelude::vec::Vec;
/// Error encountered by calling a remote contract.
///
......
......@@ -23,18 +23,16 @@
//! Users and systems are advised to share a common set of allocated buffers
//! provided by the global buffer arena.
use crate::{
env2::utils::{
EnlargeTo,
Reset,
},
memory::vec::Vec,
use crate::env2::utils::{
EnlargeTo,
Reset,
};
use cfg_if::cfg_if;
use core::cell::{
Cell,
RefCell,
};
use ink_prelude::vec::Vec;
/// The maximum amount of used byte buffers at the same time.
///
......
......@@ -14,20 +14,18 @@
use core::marker::PhantomData;
use crate::{
env2::{
call::{
state,
CallData,
Selector,
},
errors::CallError,
Env,
EnvAccessMut,
EnvTypes,
use crate::env2::{
call::{
state,
CallData,
Selector,
},
memory::vec::Vec,
errors::CallError,
Env,
EnvAccessMut,
EnvTypes,
};
use ink_prelude::vec::Vec;
/// Represents a return type.
///
......
......@@ -14,19 +14,17 @@
use core::marker::PhantomData;
use crate::{
env2::{
call::{
CallData,
Selector,
},
errors::CreateError,
Env,
EnvAccessMut,
EnvTypes,
use crate::env2::{
call::{
CallData,
Selector,
},
memory::vec::Vec,
errors::CreateError,
Env,
EnvAccessMut,
EnvTypes,
};
use ink_prelude::vec::Vec;
pub mod state {
pub use crate::env2::call::state::{
......
......@@ -13,8 +13,7 @@
// limitations under the License.
use derive_more::From;
use crate::memory::{
use ink_prelude::{
vec,
vec::Vec,
};
......
......@@ -30,7 +30,6 @@ use crate::{
SetProperty,
Topics,
},
memory::vec::Vec,
storage::{
alloc::{
Allocate,
......@@ -41,6 +40,7 @@ use crate::{
Key,
},
};
use ink_prelude::vec::Vec;
#[cfg_attr(feature = "ink-generate-abi", derive(type_metadata::Metadata))]
#[derive(Debug)]
......
......@@ -23,14 +23,12 @@
use core::borrow::Borrow;
use crate::{
env2::test::{
storage::Storage,
types::*,
TypedEncoded,
},
memory::collections::btree_map::BTreeMap,
use crate::env2::test::{
storage::Storage,
types::*,
TypedEncoded,
};
use ink_prelude::collections::btree_map::BTreeMap;
/// The on-chain registered accounts.
///
......
......@@ -39,9 +39,9 @@ use crate::{
EnvTypes,
Topics,
},
memory::vec::Vec,
storage::Key,
};
use ink_prelude::vec::Vec;
/// A record of an event happening on the off-chain test environment.
///
......
......@@ -20,12 +20,10 @@
use core::cell::Cell;
use crate::{
memory::collections::btree_map::{
self,
BTreeMap,
},
storage::Key,
use crate::storage::Key;
use ink_prelude::collections::btree_map::{
self,
BTreeMap,
};
/// An entry in the storage of the test environment.
......
......@@ -35,9 +35,9 @@ use type_metadata::Metadata;
use crate::{
env2::EnvTypes,
memory::vec::Vec,
storage::Flush,
};
use ink_prelude::vec::Vec;
/// The fundamental types of the SRML default configuration.
#[cfg_attr(feature = "test-env", derive(Debug, Clone, PartialEq, Eq))]
......
......@@ -14,13 +14,12 @@
//! Utility definitions used for environmental access.
use ink_prelude::vec::Vec;
use smallvec::{
Array,
SmallVec,
};
use crate::memory::vec::Vec;
/// Buffers that allow to reset themselves.
///
/// # Note
......
......@@ -47,16 +47,12 @@
#[cfg(not(feature = "std"))]
extern crate ink_alloc;
#[cfg(not(feature = "std"))]
extern crate alloc;
#[cfg(all(test, feature = "std"))]
mod test_utils;
mod byte_utils;
pub mod env;
pub mod env2;
pub mod memory;
pub mod storage;
// Needed for derive macros of `core/derive` sub crate.
......
// Copyright 2018-2019 Parity Technologies (UK) Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Data structures to operate on main memory.
//!
//! These definitions are useful since we are operating in a `no_std` environment.
#[cfg(not(feature = "std"))]
mod no_std_defs {
pub use alloc::{
borrow,
boxed,
format,
string,
vec,
};
/// Collection types.
pub mod collections {
pub use self::{
BTreeMap,
BTreeSet,
BinaryHeap,
LinkedList,
VecDeque,
};
pub use alloc::collections::*;
pub use core::ops::Bound;
}
}
#[cfg(feature = "std")]
mod std_defs {
pub use std::{
borrow,
boxed,
format,
string,
vec,
};
/// Collection types.
pub mod collections {
pub use self::{
binary_heap::BinaryHeap,
btree_map::BTreeMap,
btree_set::BTreeSet,
linked_list::LinkedList,
vec_deque::VecDeque,
Bound,
};
pub use std::collections::*;
}
}
#[cfg(not(feature = "std"))]
#[doc(inline)]
pub use self::no_std_defs::*;
#[cfg(feature = "std")]
#[doc(inline)]
pub use self::std_defs::*;
......@@ -12,14 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use scale::{
Decode,
Encode,
};
use crate::{
env,
memory::vec::Vec,
storage::{
alloc::{
Allocate,
......@@ -29,6 +23,11 @@ use crate::{
NonCloneMarker,
},
};
use ink_prelude::vec::Vec;
use scale::{
Decode,
Encode,
};
/// A raw cell.
///
......
......@@ -30,18 +30,16 @@ use type_metadata::{
TypeId,
};
use crate::{
memory::boxed::Box,
storage::{
alloc::{
Allocate,
AllocateUsing,
},
cell::TypedCell,
Flush,
Key,
use crate::storage::{
alloc::{
Allocate,
AllocateUsing,
},
cell::TypedCell,
Flush,
Key,
};
use ink_prelude::boxed::Box;
/// A synchronized cell.
///
......
......@@ -14,7 +14,6 @@
use crate::{
env,
memory::vec::Vec,
storage::{
alloc::{
Allocate,
......@@ -24,6 +23,7 @@ use crate::{
NonCloneMarker,
},
};
use ink_prelude::vec::Vec;
/// A chunk of raw cells.
///
......
......@@ -13,8 +13,7 @@
// limitations under the License.
use core::cell::RefCell;
use crate::memory::collections::btree_map::{
use ink_prelude::collections::btree_map::{
BTreeMap,
Entry,
};
......
......@@ -154,7 +154,7 @@ where
}
}
impl<T> Flush for crate::memory::vec::Vec<T>
impl<T> Flush for ink_prelude::vec::Vec<T>
where
T: Flush,
{
......@@ -165,9 +165,9 @@ where
}
}
impl Flush for crate::memory::string::String {}
impl Flush for ink_prelude::string::String {}
impl<K, V> Flush for crate::memory::collections::btree_map::BTreeMap<K, V>
impl<K, V> Flush for ink_prelude::collections::btree_map::BTreeMap<K, V>
where
V: Flush,
{
......@@ -179,9 +179,9 @@ where
}
}
impl<T> Flush for crate::memory::collections::btree_set::BTreeSet<T> {}
impl<T> Flush for ink_prelude::collections::btree_set::BTreeSet<T> {}
impl<T> Flush for crate::memory::collections::linked_list::LinkedList<T>
impl<T> Flush for ink_prelude::collections::linked_list::LinkedList<T>
where
T: Flush,
{
......@@ -192,7 +192,7 @@ where
}
}
impl<T> Flush for crate::memory::collections::vec_deque::VecDeque<T>
impl<T> Flush for ink_prelude::collections::vec_deque::VecDeque<T>
where
T: Flush,
{
......@@ -203,4 +203,4 @@ where
}
}
impl<T> Flush for crate::memory::collections::binary_heap::BinaryHeap<T> {}
impl<T> Flush for ink_prelude::collections::binary_heap::BinaryHeap<T> {}
......@@ -14,11 +14,9 @@
#![cfg_attr(not(feature = "std"), no_std)]
use ink_core::{
memory::format,
storage,
};
use ink_core::storage;
use ink_lang::contract;
use ink_prelude::format;
contract! {
#![env = ink_core::env::DefaultSrmlTypes]
......
......@@ -14,11 +14,9 @@
#![cfg_attr(not(feature = "std"), no_std)]
use ink_core::{
memory::format,
storage,
};
use ink_core::storage;
use ink_lang::contract;
use ink_prelude::format;
contract! {
#![env = ink_core::env::DefaultSrmlTypes]
......
......@@ -14,11 +14,9 @@
#![cfg_attr(not(feature = "std"), no_std)]
use ink_core::{
memory::format,
storage,
};
use ink_core::storage;
use ink_lang::contract;
use ink_prelude::format;
#[derive(Debug, Copy, Clone, PartialEq, Eq, scale::Encode, scale::Decode)]
#[cfg_attr(feature = "ink-generate-abi", derive(type_metadata::Metadata))]
......
......@@ -14,11 +14,9 @@
#![cfg_attr(not(feature = "std"), no_std)]
use ink_core::{
memory::format,
storage,
};
use ink_core::storage;
use ink_lang::contract;
use ink_prelude::format;
contract! {
#![env = ink_core::env::DefaultSrmlTypes]
......
......@@ -16,11 +16,11 @@
use ink_core::{
env::DefaultSrmlTypes,
memory::format,
storage,
};
use ink_lang::contract;
use ink_model::EnvHandler;
use ink_prelude::format;
contract! {
#![env = DefaultSrmlTypes]
......
......@@ -17,11 +17,11 @@
use core::result::Result;
use ink_core::{
env::DefaultSrmlTypes,
memory::format,
storage,
};
use ink_lang::contract;
use ink_model;
use ink_prelude::format;
use scale::{
Decode,
Encode,
......
......@@ -16,10 +16,10 @@
use ink_core::{
env::DefaultSrmlTypes,
memory::format,
storage,
};
use ink_lang::contract;
use ink_prelude::format;
contract! {
#![env = DefaultSrmlTypes]
......
......@@ -14,11 +14,9 @@
#![cfg_attr(not(feature = "std"), no_std)]
use ink_core::{
memory::format,
storage,
};
use ink_core::storage;
use ink_lang::contract;
use ink_prelude::format;
contract! {
#![env = ink_core::env::DefaultSrmlTypes]
......
......@@ -17,6 +17,7 @@ include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"]
[dependencies]
ink_utils = { path = "../utils/" }
ink_model = { path = "../model/", default-features = false }
ink_prelude = { path = "../prelude/", default-features = false }
scale = { package = "parity-scale-codec", version = "1.1", default-features = false, features = ["derive"] }
quote = "1.0"