mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-26 13:31:07 +00:00
6cfdbe5caa
* starting * Updated from other branch. * setting flag * flag in storage struct * fix flagging to access and insert. * added todo to fix * also missing serialize meta to storage proof * extract meta. * Isolate old trie layout. * failing test that requires storing in meta when old hash scheme is used. * old hash compatibility * Db migrate. * runing tests with both states when interesting. * fix chain spec test with serde default. * export state (missing trie function). * Pending using new branch, lacking genericity on layout resolution. * extract and set global meta * Update to branch 4 * fix iterator with root flag (no longer insert node). * fix trie root hashing of root * complete basic backend. * Remove old_hash meta from proof that do not use inner_hashing. * fix trie test for empty (force layout on empty deltas). * Root update fix. * debug on meta * Use trie key iteration that do not include value in proofs. * switch default test ext to use inner hash. * small integration test, and fix tx cache mgmt in ext. test failing * Proof scenario at state-machine level. * trace for db upgrade * try different param * act more like iter_from. * Bigger batches. * Update trie dependency. * drafting codec changes and refact * before removing unused branch no value alt hashing. more work todo rename all flag var to alt_hash, and remove extrinsic replace by storage query at every storage_root call. * alt hashing only for branch with value. * fix trie tests * Hash of value include the encoded size. * removing fields(broken) * fix trie_stream to also include value length in inner hash. * triedbmut only using alt type if inner hashing. * trie_stream to also only use alt hashing type when actually alt hashing. * Refactor meta state, logic should work with change of trie treshold. * Remove NoMeta variant. * Remove state_hashed trigger specific functions. * pending switching to using threshold, new storage root api does not make much sense. * refactoring to use state from backend (not possible payload changes). * Applying from previous state * Remove default from storage, genesis need a special build. * rem empty space * Catch problem: when using triedb with default: we should not revert nodes: otherwhise thing as trie codec cannot decode-encode without changing state. * fix compilation * Right logic to avoid switch on reencode when default layout. * Clean up some todos * remove trie meta from root upstream * update upstream and fix benches. * split some long lines. * UPdate trie crate to work with new design. * Finish update to refactored upstream. * update to latest triedb changes. * Clean up. * fix executor test. * rust fmt from master. * rust format. * rustfmt * fix * start host function driven versioning * update state-machine part * still need access to state version from runtime * state hash in mem: wrong * direction likely correct, but passing call to code exec for genesis init seem awkward. * state version serialize in runtime, wrong approach, just initialize it with no threshold for core api < 4 seems more proper. * stateversion from runtime version (core api >= 4). * update trie, fix tests * unused import * clean some TODOs * Require RuntimeVersionOf for executor * use RuntimeVersionOf to resolve genesis state version. * update runtime version test * fix state-machine tests * TODO * Use runtime version from storage wasm with fast sync. * rustfmt * fmt * fix test * revert useless changes. * clean some unused changes * fmt * removing useless trait function. * remove remaining reference to state_hash * fix some imports * Follow chain state version management. * trie update, fix and constant threshold for trie layouts. * update deps * Update to latest trie pr changes. * fix benches * Verify proof requires right layout. * update trie_root * Update trie deps to latest * Update to latest trie versioning * Removing patch * update lock * extrinsic for sc-service-test using layout v0. * Adding RuntimeVersionOf to CallExecutor works. * fmt * error when resolving version and no wasm in storage. * use existing utils to instantiate runtime code. * migration pallet * Patch to delay runtime switch. * Revert "Patch to delay runtime switch." This reverts commit 67e55fee468f1a0cda853f5362b22e0d775786da. * fix test * fix child migration calls. * useless closure * remove remaining state_hash variables. * Fix and add more tests * Remove outdated comment * useless inner hash * fmt * remote tests * finally ksm works * batches are broken * clean the benchmarks * Apply suggestions from code review Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Apply suggestions from code review Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Update frame/state-trie-migration/src/lib.rs Co-authored-by: Joshy Orndorff <JoshOrndorff@users.noreply.github.com> * Update frame/state-trie-migration/src/lib.rs * brand new version * fix build * Update frame/state-trie-migration/src/lib.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Update frame/state-trie-migration/src/lib.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Update primitives/storage/src/lib.rs Co-authored-by: cheme <emericchevalier.pro@gmail.com> * Update frame/state-trie-migration/src/lib.rs Co-authored-by: cheme <emericchevalier.pro@gmail.com> * Update frame/state-trie-migration/src/lib.rs Co-authored-by: cheme <emericchevalier.pro@gmail.com> * fmt and opt-in feature to apply state change. * feature gate core version, use new test feature for node and test node * Use a 'State' api version instead of Core one. * fix merge of test function * use blake macro. * Fix state api (require declaring the api in runtime). * Opt out feature, fix macro for io to select a given version instead of latest. * run test nodes on new state. * fix * new test structure * new testing stuff from emeric * Add commit_all, still not working * Fix all tests * add comment * we have PoV tracking baby * document stuff, but proof size is still wrong * FUCK YEAH * a big batch of review comments * add more tests * tweak test * update config * some remote-ext stuff * delete some of the old stuff * sync more files with master to minimize the diff * Fix all tests * make signed migration a bit more relaxed * add witness check to signed submissions * allow custom migration to also go above limit * Fix these pesky tests * ==== removal of the unsigned stuff ==== * Make all tests work again * separate the tests from the logic so it can be reused easier * fix overall build * Update frame/state-trie-migration/src/lib.rs Co-authored-by: cheme <emericchevalier.pro@gmail.com> * Update frame/state-trie-migration/src/lib.rs Co-authored-by: cheme <emericchevalier.pro@gmail.com> * Slightly better termination * some final tweaks * Fix tests * Restrict access to signed migrations * address most of the review comments * fix defensive * New simplified code * Fix weights * fmt * Update frame/state-trie-migration/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * make the tests correctly fail * Fix build * Fix build * try and fix the benchmarks * fix build * Fix cargo file * Fix runtime deposit * make rustdoc happy * cargo run --quiet --profile=production --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_state_trie_migration --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/state-trie-migration/src/weights.rs --template=./.maintain/frame-weight-template.hbs Co-authored-by: cheme <emericchevalier.pro@gmail.com> Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> Co-authored-by: Joshy Orndorff <JoshOrndorff@users.noreply.github.com> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Parity Bot <admin@parity.io>
469 lines
12 KiB
Rust
469 lines
12 KiB
Rust
// This file is part of Substrate.
|
|
|
|
// Copyright (C) 2017-2022 Parity Technologies (UK) Ltd.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// 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.
|
|
|
|
//! Shareable Substrate types.
|
|
|
|
#![warn(missing_docs)]
|
|
#![cfg_attr(not(feature = "std"), no_std)]
|
|
|
|
/// Initialize a key-value collection from array.
|
|
///
|
|
/// Creates a vector of given pairs and calls `collect` on the iterator from it.
|
|
/// Can be used to create a `HashMap`.
|
|
#[macro_export]
|
|
macro_rules! map {
|
|
($( $name:expr => $value:expr ),* $(,)? ) => (
|
|
vec![ $( ( $name, $value ) ),* ].into_iter().collect()
|
|
);
|
|
}
|
|
|
|
#[doc(hidden)]
|
|
pub use codec::{Decode, Encode};
|
|
use scale_info::TypeInfo;
|
|
#[cfg(feature = "std")]
|
|
pub use serde;
|
|
#[cfg(feature = "std")]
|
|
use serde::{Deserialize, Serialize};
|
|
use sp_runtime_interface::pass_by::{PassByEnum, PassByInner};
|
|
use sp_std::{ops::Deref, prelude::*};
|
|
#[cfg(feature = "std")]
|
|
use std::borrow::Cow;
|
|
|
|
pub use sp_debug_derive::RuntimeDebug;
|
|
|
|
#[cfg(feature = "std")]
|
|
pub use impl_serde::serialize as bytes;
|
|
|
|
#[cfg(feature = "full_crypto")]
|
|
pub mod hashing;
|
|
|
|
#[cfg(feature = "full_crypto")]
|
|
pub use hashing::{blake2_128, blake2_256, keccak_256, twox_128, twox_256, twox_64};
|
|
pub mod crypto;
|
|
pub mod hexdisplay;
|
|
|
|
pub mod ecdsa;
|
|
pub mod ed25519;
|
|
pub mod hash;
|
|
#[cfg(feature = "std")]
|
|
mod hasher;
|
|
pub mod offchain;
|
|
pub mod sandbox;
|
|
pub mod sr25519;
|
|
pub mod testing;
|
|
#[cfg(feature = "std")]
|
|
pub mod traits;
|
|
pub mod uint;
|
|
|
|
pub use self::{
|
|
hash::{convert_hash, H160, H256, H512},
|
|
uint::{U256, U512},
|
|
};
|
|
#[cfg(feature = "full_crypto")]
|
|
pub use crypto::{ByteArray, DeriveJunction, Pair, Public};
|
|
|
|
#[cfg(feature = "std")]
|
|
pub use self::hasher::blake2::Blake2Hasher;
|
|
#[cfg(feature = "std")]
|
|
pub use self::hasher::keccak::KeccakHasher;
|
|
pub use hash_db::Hasher;
|
|
|
|
pub use sp_storage as storage;
|
|
|
|
#[doc(hidden)]
|
|
pub use sp_std;
|
|
|
|
/// Context for executing a call into the runtime.
|
|
pub enum ExecutionContext {
|
|
/// Context used for general block import (including locally authored blocks).
|
|
Importing,
|
|
/// Context used for importing blocks as part of an initial sync of the blockchain.
|
|
///
|
|
/// We distinguish between major sync and import so that validators who are running
|
|
/// their initial sync (or catching up after some time offline) can use the faster
|
|
/// native runtime (since we can reasonably assume the network as a whole has already
|
|
/// come to a broad consensus on the block and it probably hasn't been crafted
|
|
/// specifically to attack this node), but when importing blocks at the head of the
|
|
/// chain in normal operation they can use the safer Wasm version.
|
|
Syncing,
|
|
/// Context used for block construction.
|
|
BlockConstruction,
|
|
/// Context used for offchain calls.
|
|
///
|
|
/// This allows passing offchain extension and customizing available capabilities.
|
|
OffchainCall(Option<(Box<dyn offchain::Externalities>, offchain::Capabilities)>),
|
|
}
|
|
|
|
impl ExecutionContext {
|
|
/// Returns the capabilities of particular context.
|
|
pub fn capabilities(&self) -> offchain::Capabilities {
|
|
use ExecutionContext::*;
|
|
|
|
match self {
|
|
Importing | Syncing | BlockConstruction => offchain::Capabilities::empty(),
|
|
// Enable keystore, transaction pool and Offchain DB reads by default for offchain
|
|
// calls.
|
|
OffchainCall(None) =>
|
|
offchain::Capabilities::KEYSTORE |
|
|
offchain::Capabilities::OFFCHAIN_DB_READ |
|
|
offchain::Capabilities::TRANSACTION_POOL,
|
|
OffchainCall(Some((_, capabilities))) => *capabilities,
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Hex-serialized shim for `Vec<u8>`.
|
|
#[derive(PartialEq, Eq, Clone, RuntimeDebug)]
|
|
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Hash, PartialOrd, Ord))]
|
|
pub struct Bytes(#[cfg_attr(feature = "std", serde(with = "bytes"))] pub Vec<u8>);
|
|
|
|
impl From<Vec<u8>> for Bytes {
|
|
fn from(s: Vec<u8>) -> Self {
|
|
Bytes(s)
|
|
}
|
|
}
|
|
|
|
impl From<OpaqueMetadata> for Bytes {
|
|
fn from(s: OpaqueMetadata) -> Self {
|
|
Bytes(s.0)
|
|
}
|
|
}
|
|
|
|
impl Deref for Bytes {
|
|
type Target = [u8];
|
|
fn deref(&self) -> &[u8] {
|
|
&self.0[..]
|
|
}
|
|
}
|
|
|
|
impl codec::WrapperTypeEncode for Bytes {}
|
|
|
|
impl codec::WrapperTypeDecode for Bytes {
|
|
type Wrapped = Vec<u8>;
|
|
}
|
|
|
|
#[cfg(feature = "std")]
|
|
impl sp_std::str::FromStr for Bytes {
|
|
type Err = bytes::FromHexError;
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
bytes::from_hex(s).map(Bytes)
|
|
}
|
|
}
|
|
|
|
/// Stores the encoded `RuntimeMetadata` for the native side as opaque type.
|
|
#[derive(Encode, Decode, PartialEq)]
|
|
pub struct OpaqueMetadata(Vec<u8>);
|
|
|
|
impl OpaqueMetadata {
|
|
/// Creates a new instance with the given metadata blob.
|
|
pub fn new(metadata: Vec<u8>) -> Self {
|
|
OpaqueMetadata(metadata)
|
|
}
|
|
}
|
|
|
|
impl sp_std::ops::Deref for OpaqueMetadata {
|
|
type Target = Vec<u8>;
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
&self.0
|
|
}
|
|
}
|
|
|
|
/// Simple blob to hold a `PeerId` without committing to its format.
|
|
#[derive(
|
|
Default,
|
|
Clone,
|
|
Eq,
|
|
PartialEq,
|
|
Ord,
|
|
PartialOrd,
|
|
Encode,
|
|
Decode,
|
|
RuntimeDebug,
|
|
PassByInner,
|
|
TypeInfo,
|
|
)]
|
|
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
|
pub struct OpaquePeerId(pub Vec<u8>);
|
|
|
|
impl OpaquePeerId {
|
|
/// Create new `OpaquePeerId`
|
|
pub fn new(vec: Vec<u8>) -> Self {
|
|
OpaquePeerId(vec)
|
|
}
|
|
}
|
|
|
|
/// Something that is either a native or an encoded value.
|
|
#[cfg(feature = "std")]
|
|
pub enum NativeOrEncoded<R> {
|
|
/// The native representation.
|
|
Native(R),
|
|
/// The encoded representation.
|
|
Encoded(Vec<u8>),
|
|
}
|
|
|
|
#[cfg(feature = "std")]
|
|
impl<R> From<R> for NativeOrEncoded<R> {
|
|
fn from(val: R) -> Self {
|
|
Self::Native(val)
|
|
}
|
|
}
|
|
|
|
#[cfg(feature = "std")]
|
|
impl<R: codec::Encode> sp_std::fmt::Debug for NativeOrEncoded<R> {
|
|
fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
|
|
hexdisplay::HexDisplay::from(&self.as_encoded().as_ref()).fmt(f)
|
|
}
|
|
}
|
|
|
|
#[cfg(feature = "std")]
|
|
impl<R: codec::Encode> NativeOrEncoded<R> {
|
|
/// Return the value as the encoded format.
|
|
pub fn as_encoded(&self) -> Cow<'_, [u8]> {
|
|
match self {
|
|
NativeOrEncoded::Encoded(e) => Cow::Borrowed(e.as_slice()),
|
|
NativeOrEncoded::Native(n) => Cow::Owned(n.encode()),
|
|
}
|
|
}
|
|
|
|
/// Return the value as the encoded format.
|
|
pub fn into_encoded(self) -> Vec<u8> {
|
|
match self {
|
|
NativeOrEncoded::Encoded(e) => e,
|
|
NativeOrEncoded::Native(n) => n.encode(),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(feature = "std")]
|
|
impl<R: PartialEq + codec::Decode> PartialEq for NativeOrEncoded<R> {
|
|
fn eq(&self, other: &Self) -> bool {
|
|
match (self, other) {
|
|
(NativeOrEncoded::Native(l), NativeOrEncoded::Native(r)) => l == r,
|
|
(NativeOrEncoded::Native(n), NativeOrEncoded::Encoded(e)) |
|
|
(NativeOrEncoded::Encoded(e), NativeOrEncoded::Native(n)) =>
|
|
Some(n) == codec::Decode::decode(&mut &e[..]).ok().as_ref(),
|
|
(NativeOrEncoded::Encoded(l), NativeOrEncoded::Encoded(r)) => l == r,
|
|
}
|
|
}
|
|
}
|
|
|
|
/// A value that is never in a native representation.
|
|
/// This is type is useful in conjunction with `NativeOrEncoded`.
|
|
#[cfg(feature = "std")]
|
|
#[derive(PartialEq)]
|
|
pub enum NeverNativeValue {}
|
|
|
|
#[cfg(feature = "std")]
|
|
impl codec::Encode for NeverNativeValue {
|
|
fn encode(&self) -> Vec<u8> {
|
|
// The enum is not constructable, so this function should never be callable!
|
|
unreachable!()
|
|
}
|
|
}
|
|
|
|
#[cfg(feature = "std")]
|
|
impl codec::EncodeLike for NeverNativeValue {}
|
|
|
|
#[cfg(feature = "std")]
|
|
impl codec::Decode for NeverNativeValue {
|
|
fn decode<I: codec::Input>(_: &mut I) -> Result<Self, codec::Error> {
|
|
Err("`NeverNativeValue` should never be decoded".into())
|
|
}
|
|
}
|
|
|
|
/// Provide a simple 4 byte identifier for a type.
|
|
pub trait TypeId {
|
|
/// Simple 4 byte identifier.
|
|
const TYPE_ID: [u8; 4];
|
|
}
|
|
|
|
/// A log level matching the one from `log` crate.
|
|
///
|
|
/// Used internally by `sp_io::logging::log` method.
|
|
#[derive(Encode, Decode, PassByEnum, Copy, Clone)]
|
|
pub enum LogLevel {
|
|
/// `Error` log level.
|
|
Error = 1_isize,
|
|
/// `Warn` log level.
|
|
Warn = 2_isize,
|
|
/// `Info` log level.
|
|
Info = 3_isize,
|
|
/// `Debug` log level.
|
|
Debug = 4_isize,
|
|
/// `Trace` log level.
|
|
Trace = 5_isize,
|
|
}
|
|
|
|
impl From<u32> for LogLevel {
|
|
fn from(val: u32) -> Self {
|
|
match val {
|
|
x if x == LogLevel::Warn as u32 => LogLevel::Warn,
|
|
x if x == LogLevel::Info as u32 => LogLevel::Info,
|
|
x if x == LogLevel::Debug as u32 => LogLevel::Debug,
|
|
x if x == LogLevel::Trace as u32 => LogLevel::Trace,
|
|
_ => LogLevel::Error,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<log::Level> for LogLevel {
|
|
fn from(l: log::Level) -> Self {
|
|
use log::Level::*;
|
|
match l {
|
|
Error => Self::Error,
|
|
Warn => Self::Warn,
|
|
Info => Self::Info,
|
|
Debug => Self::Debug,
|
|
Trace => Self::Trace,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<LogLevel> for log::Level {
|
|
fn from(l: LogLevel) -> Self {
|
|
use self::LogLevel::*;
|
|
match l {
|
|
Error => Self::Error,
|
|
Warn => Self::Warn,
|
|
Info => Self::Info,
|
|
Debug => Self::Debug,
|
|
Trace => Self::Trace,
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Log level filter that expresses which log levels should be filtered.
|
|
///
|
|
/// This enum matches the [`log::LevelFilter`] enum.
|
|
#[derive(Encode, Decode, PassByEnum, Copy, Clone)]
|
|
pub enum LogLevelFilter {
|
|
/// `Off` log level filter.
|
|
Off = 0_isize,
|
|
/// `Error` log level filter.
|
|
Error = 1_isize,
|
|
/// `Warn` log level filter.
|
|
Warn = 2_isize,
|
|
/// `Info` log level filter.
|
|
Info = 3_isize,
|
|
/// `Debug` log level filter.
|
|
Debug = 4_isize,
|
|
/// `Trace` log level filter.
|
|
Trace = 5_isize,
|
|
}
|
|
|
|
impl From<LogLevelFilter> for log::LevelFilter {
|
|
fn from(l: LogLevelFilter) -> Self {
|
|
use self::LogLevelFilter::*;
|
|
match l {
|
|
Off => Self::Off,
|
|
Error => Self::Error,
|
|
Warn => Self::Warn,
|
|
Info => Self::Info,
|
|
Debug => Self::Debug,
|
|
Trace => Self::Trace,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<log::LevelFilter> for LogLevelFilter {
|
|
fn from(l: log::LevelFilter) -> Self {
|
|
use log::LevelFilter::*;
|
|
match l {
|
|
Off => Self::Off,
|
|
Error => Self::Error,
|
|
Warn => Self::Warn,
|
|
Info => Self::Info,
|
|
Debug => Self::Debug,
|
|
Trace => Self::Trace,
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Encodes the given value into a buffer and returns the pointer and the length as a single `u64`.
|
|
///
|
|
/// When Substrate calls into Wasm it expects a fixed signature for functions exported
|
|
/// from the Wasm blob. The return value of this signature is always a `u64`.
|
|
/// This `u64` stores the pointer to the encoded return value and the length of this encoded value.
|
|
/// The low `32bits` are reserved for the pointer, followed by `32bit` for the length.
|
|
#[cfg(not(feature = "std"))]
|
|
pub fn to_substrate_wasm_fn_return_value(value: &impl Encode) -> u64 {
|
|
let encoded = value.encode();
|
|
|
|
let ptr = encoded.as_ptr() as u64;
|
|
let length = encoded.len() as u64;
|
|
let res = ptr | (length << 32);
|
|
|
|
// Leak the output vector to avoid it being freed.
|
|
// This is fine in a WASM context since the heap
|
|
// will be discarded after the call.
|
|
sp_std::mem::forget(encoded);
|
|
|
|
res
|
|
}
|
|
|
|
/// The void type - it cannot exist.
|
|
// Oh rust, you crack me up...
|
|
#[derive(Clone, Decode, Encode, Eq, PartialEq, RuntimeDebug, TypeInfo)]
|
|
pub enum Void {}
|
|
|
|
/// Macro for creating `Maybe*` marker traits.
|
|
///
|
|
/// Such a maybe-marker trait requires the given bound when `feature = std` and doesn't require
|
|
/// the bound on `no_std`. This is useful for situations where you require that a type implements
|
|
/// a certain trait with `feature = std`, but not on `no_std`.
|
|
///
|
|
/// # Example
|
|
///
|
|
/// ```
|
|
/// sp_core::impl_maybe_marker! {
|
|
/// /// A marker for a type that implements `Debug` when `feature = std`.
|
|
/// trait MaybeDebug: std::fmt::Debug;
|
|
/// /// A marker for a type that implements `Debug + Display` when `feature = std`.
|
|
/// trait MaybeDebugDisplay: std::fmt::Debug, std::fmt::Display;
|
|
/// }
|
|
/// ```
|
|
#[macro_export]
|
|
macro_rules! impl_maybe_marker {
|
|
(
|
|
$(
|
|
$(#[$doc:meta] )+
|
|
trait $trait_name:ident: $( $trait_bound:path ),+;
|
|
)+
|
|
) => {
|
|
$(
|
|
$(#[$doc])+
|
|
#[cfg(feature = "std")]
|
|
pub trait $trait_name: $( $trait_bound + )+ {}
|
|
#[cfg(feature = "std")]
|
|
impl<T: $( $trait_bound + )+> $trait_name for T {}
|
|
|
|
$(#[$doc])+
|
|
#[cfg(not(feature = "std"))]
|
|
pub trait $trait_name {}
|
|
#[cfg(not(feature = "std"))]
|
|
impl<T> $trait_name for T {}
|
|
)+
|
|
}
|
|
}
|
|
|
|
/// The maximum number of bytes that can be allocated at one time.
|
|
// The maximum possible allocation size was chosen rather arbitrary, 32 MiB should be enough for
|
|
// everybody.
|
|
pub const MAX_POSSIBLE_ALLOCATION: u32 = 33554432; // 2^25 bytes, 32 MiB
|