sp-std removal from substrate/primitives (#3274)

This PR removes sp-std crate from substrate/primitives sub-directories.

For now crates that have `pub use` of sp-std or export macros that would
necessitate users of the macros to `extern crate alloc` have been
excluded from this PR.

There should be no breaking changes in this PR.

---------

Co-authored-by: Koute <koute@users.noreply.github.com>
This commit is contained in:
Squirrel
2024-03-18 05:29:35 +00:00
committed by GitHub
parent 6b1179f13b
commit 1b5f4243d1
110 changed files with 254 additions and 278 deletions
@@ -23,13 +23,13 @@ use crate::{
trie_backend_essence::TrieBackendStorage, ChildStorageCollection, StorageCollection,
StorageKey, StorageValue, UsageInfo,
};
use alloc::vec::Vec;
use codec::Encode;
use core::marker::PhantomData;
use hash_db::Hasher;
use sp_core::storage::{ChildInfo, StateVersion, TrackedStorageKey};
#[cfg(feature = "std")]
use sp_core::traits::RuntimeCode;
use sp_std::vec::Vec;
use sp_trie::{MerkleValue, PrefixedMemoryDB};
/// A struct containing arguments for iterating over the storage.
@@ -179,7 +179,7 @@ pub type BackendTransaction<H> = PrefixedMemoryDB<H>;
/// to it.
///
/// The clone operation (if implemented) should be cheap.
pub trait Backend<H: Hasher>: sp_std::fmt::Debug {
pub trait Backend<H: Hasher>: core::fmt::Debug {
/// An error type when fetching data is not possible.
type Error: super::Error;
@@ -32,12 +32,10 @@ use sp_core::storage::{
use sp_externalities::{Extension, ExtensionStore, Externalities, MultiRemovalResults};
use crate::{log_error, trace, warn};
use sp_std::{
use alloc::{boxed::Box, vec, vec::Vec};
use core::{
any::{Any, TypeId},
boxed::Box,
cmp::Ordering,
vec,
vec::Vec,
};
#[cfg(feature = "std")]
use std::error;
@@ -739,7 +737,7 @@ impl<'a> StorageAppend<'a> {
pub fn append(&mut self, value: Vec<u8>) {
let value = vec![EncodeOpaqueValue(value)];
let item = sp_std::mem::take(self.0);
let item = core::mem::take(self.0);
*self.0 = match Vec::<EncodeOpaqueValue>::append_or_new(item, &value) {
Ok(item) => item,
@@ -20,6 +20,8 @@
#![warn(missing_docs)]
#![cfg_attr(not(feature = "std"), no_std)]
extern crate alloc;
pub mod backend;
#[cfg(feature = "std")]
mod basic;
@@ -118,8 +120,8 @@ pub type DefaultError = String;
pub struct DefaultError;
#[cfg(not(feature = "std"))]
impl sp_std::fmt::Display for DefaultError {
fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
impl core::fmt::Display for DefaultError {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
write!(f, "DefaultError")
}
}
@@ -20,16 +20,14 @@
use super::{Extrinsics, StorageKey, StorageValue};
#[cfg(not(feature = "std"))]
use sp_std::collections::btree_set::BTreeSet as Set;
use alloc::collections::btree_set::BTreeSet as Set;
#[cfg(feature = "std")]
use std::collections::HashSet as Set;
use crate::warn;
use alloc::collections::{btree_map::BTreeMap, btree_set::BTreeSet};
use core::hash::Hash;
use smallvec::SmallVec;
use sp_std::{
collections::{btree_map::BTreeMap, btree_set::BTreeSet},
hash::Hash,
};
const PROOF_OVERLAY_NON_EMPTY: &str = "\
An OverlayValue is always created with at least one transaction and dropped as soon
@@ -225,7 +223,7 @@ impl<K: Ord + Hash + Clone, V> OverlayedMap<K, V> {
/// This changeset might be created when there are already open transactions.
/// We need to catch up here so that the child is at the same transaction depth.
pub fn spawn_child(&self) -> Self {
use sp_std::iter::repeat;
use core::iter::repeat;
Self {
changes: Default::default(),
dirty_keys: repeat(Set::new()).take(self.transaction_depth()).collect(),
@@ -242,7 +240,7 @@ impl<K: Ord + Hash + Clone, V> OverlayedMap<K, V> {
/// Get an optional reference to the value stored for the specified key.
pub fn get<Q>(&self, key: &Q) -> Option<&OverlayedEntry<V>>
where
K: sp_std::borrow::Borrow<Q>,
K: core::borrow::Borrow<Q>,
Q: Ord + ?Sized,
{
self.changes.get(key)
@@ -448,7 +446,7 @@ impl OverlayedChangeSet {
/// Get the iterator over all changes that follow the supplied `key`.
pub fn changes_after(&self, key: &[u8]) -> impl Iterator<Item = (&[u8], &OverlayedValue)> {
use sp_std::ops::Bound;
use core::ops::Bound;
let range = (Bound::Excluded(key), Bound::Unbounded);
self.changes.range::<[u8], _>(range).map(|(k, v)| (k.as_slice(), v))
}
@@ -22,6 +22,7 @@ mod offchain;
use self::changeset::OverlayedChangeSet;
use crate::{backend::Backend, stats::StateMachineStats, BackendTransaction, DefaultError};
use alloc::{collections::btree_set::BTreeSet, vec::Vec};
use codec::{Decode, Encode};
use hash_db::Hasher;
pub use offchain::OffchainOverlayedChanges;
@@ -31,12 +32,13 @@ use sp_core::{
};
#[cfg(feature = "std")]
use sp_externalities::{Extension, Extensions};
#[cfg(not(feature = "std"))]
use sp_std::collections::btree_map::BTreeMap as Map;
use sp_std::{collections::btree_set::BTreeSet, vec::Vec};
use sp_trie::{empty_child_trie_root, LayoutV1};
#[cfg(not(feature = "std"))]
use alloc::collections::btree_map::BTreeMap as Map;
#[cfg(feature = "std")]
use std::collections::{hash_map::Entry as MapEntry, HashMap as Map};
#[cfg(feature = "std")]
use std::{
any::{Any, TypeId},
@@ -136,7 +138,7 @@ impl<H: Hasher> Clone for OverlayedChanges<H> {
}
}
impl<H: Hasher> sp_std::fmt::Debug for OverlayedChanges<H> {
impl<H: Hasher> core::fmt::Debug for OverlayedChanges<H> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("OverlayedChanges")
.field("top", &self.top)
@@ -259,7 +261,7 @@ impl<H: Hasher> Clone for StorageTransactionCache<H> {
}
}
impl<H: Hasher> sp_std::fmt::Debug for StorageTransactionCache<H> {
impl<H: Hasher> core::fmt::Debug for StorageTransactionCache<H> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let mut debug = f.debug_struct("StorageTransactionCache");
@@ -572,7 +574,7 @@ impl<H: Hasher> OverlayedChanges<H> {
},
};
use sp_std::mem::take;
use core::mem::take;
let main_storage_changes = take(&mut self.top).drain_commited();
let child_storage_changes = take(&mut self.children)
.into_iter()
@@ -777,7 +779,7 @@ where
K: Ord,
F: FnMut(&K, &mut V) -> bool,
{
let old = sp_std::mem::replace(map, Map::default());
let old = core::mem::replace(map, Map::default());
for (k, mut v) in old.into_iter() {
if f(&k, &mut v) {
map.insert(k, v);
@@ -18,8 +18,8 @@
//! Overlayed changes for offchain indexing.
use super::changeset::OverlayedMap;
use alloc::vec::Vec;
use sp_core::offchain::OffchainOverlayedChange;
use sp_std::prelude::Vec;
/// In-memory storage for offchain workers recoding changes for the actual offchain storage
/// implementation.
@@ -48,7 +48,7 @@ impl OffchainOverlayedChanges {
/// Drain all elements of changeset.
pub fn drain(&mut self) -> impl Iterator<Item = OffchainOverlayedChangesItemOwned> {
sp_std::mem::take(self).into_iter()
core::mem::take(self).into_iter()
}
/// Remove a key and its associated value from the offchain database.
@@ -297,7 +297,7 @@ struct CachedIter<S, H, C, R>
where
H: Hasher,
{
last_key: sp_std::vec::Vec<u8>,
last_key: alloc::vec::Vec<u8>,
iter: RawIter<S, H, C, R>,
}
@@ -390,9 +390,9 @@ where
}
impl<S: TrieBackendStorage<H>, H: Hasher, C: TrieCacheProvider<H>, R: TrieRecorderProvider<H>>
sp_std::fmt::Debug for TrieBackend<S, H, C, R>
core::fmt::Debug for TrieBackend<S, H, C, R>
{
fn fmt(&self, f: &mut sp_std::fmt::Formatter<'_>) -> sp_std::fmt::Result {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "TrieBackend")
}
}
@@ -23,14 +23,15 @@ use crate::{
trie_backend::TrieCacheProvider,
warn, StorageKey, StorageValue,
};
#[cfg(feature = "std")]
use alloc::sync::Arc;
use alloc::{boxed::Box, vec::Vec};
use codec::Codec;
use core::marker::PhantomData;
use hash_db::{self, AsHashDB, HashDB, HashDBRef, Hasher, Prefix};
#[cfg(feature = "std")]
use parking_lot::RwLock;
use sp_core::storage::{ChildInfo, ChildType, StateVersion};
#[cfg(feature = "std")]
use sp_std::sync::Arc;
use sp_std::{boxed::Box, marker::PhantomData, vec::Vec};
use sp_trie::{
child_delta_trie_root, delta_trie_root, empty_child_trie_root,
read_child_trie_first_descedant_value, read_child_trie_hash, read_child_trie_value,
@@ -55,7 +56,7 @@ macro_rules! format {
};
}
type Result<V> = sp_std::result::Result<V, crate::DefaultError>;
type Result<V> = core::result::Result<V, crate::DefaultError>;
/// Patricia trie-based storage trait.
pub trait Storage<H: Hasher>: Send + Sync {