ink_prelude/lib.rs
1// Copyright (C) Use Ink (UK) Ltd.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Data structures to operate on contract memory during contract execution.
16//!
17//! These definitions are useful since we are operating in a `no_std` environment
18//! and should be used by all ink! crates instead of directly using `std` or `alloc`
19//! crates. If needed we shall instead enhance the exposed types here.
20//!
21//! The `ink_prelude` crate guarantees a stable interface between `std` and `no_std` mode.
22
23#![doc(
24 html_logo_url = "https://use.ink/img/crate-docs/logo.png",
25 html_favicon_url = "https://use.ink/crate-docs/favicon.png"
26)]
27#![cfg_attr(not(feature = "std"), no_std)]
28
29#[cfg(not(feature = "std"))]
30extern crate alloc;
31
32use cfg_if::cfg_if;
33
34/// A well know selector reserved for the message required to be defined
35/// alongside a wildcard selector. See [IIP-2](https://github.com/use-ink/ink/issues/1676).
36///
37/// Calculated from `selector_bytes!("IIP2_WILDCARD_COMPLEMENT")`
38pub const IIP2_WILDCARD_COMPLEMENT_SELECTOR: [u8; 4] = [0x9B, 0xAE, 0x9D, 0x5E];
39
40cfg_if! {
41 if #[cfg(feature = "std")] {
42 pub use std::{
43 borrow,
44 boxed,
45 format,
46 string,
47 vec,
48 };
49
50 /// Collection types.
51 pub mod collections {
52 pub use self::{
53 binary_heap::BinaryHeap,
54 btree_map::BTreeMap,
55 btree_set::BTreeSet,
56 linked_list::LinkedList,
57 vec_deque::VecDeque,
58 Bound,
59 };
60 pub use std::collections::*;
61 }
62 } else {
63 pub use alloc::{
64 borrow,
65 boxed,
66 format,
67 string,
68 vec,
69 };
70 //pub use core::sync::Mutex;
71 //pub use sync::Mutex;
72
73 /// Collection types.
74 pub mod collections {
75 pub use self::{
76 BTreeMap,
77 BTreeSet,
78 BinaryHeap,
79 LinkedList,
80 VecDeque,
81 };
82 pub use alloc::collections::*;
83 pub use core::ops::Bound;
84 }
85 }
86}