diff --git a/Cargo.lock b/Cargo.lock index 1cb864285b..4fd98a19cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4578,7 +4578,6 @@ version = "0.34.0" dependencies = [ "assert_matches", "bitvec", - "cfg-if", "criterion", "derive_more", "frame-metadata 16.0.0", diff --git a/metadata/Cargo.toml b/metadata/Cargo.toml index e1391650b6..a6e15de0aa 100644 --- a/metadata/Cargo.toml +++ b/metadata/Cargo.toml @@ -24,7 +24,6 @@ codec = { package = "parity-scale-codec", workspace = true, default-features = f sp-core-hashing = { workspace = true } hashbrown = { workspace = true } derive_more = { workspace = true } -cfg-if = { workspace = true } [dev-dependencies] bitvec = { workspace = true, features = ["alloc"] } diff --git a/metadata/src/from_into/mod.rs b/metadata/src/from_into/mod.rs index 33074a2db0..1a950e1d5a 100644 --- a/metadata/src/from_into/mod.rs +++ b/metadata/src/from_into/mod.rs @@ -2,9 +2,8 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::prelude::*; +use alloc::string::String; use derive_more::Display; -use string::String; mod v14; mod v15; diff --git a/metadata/src/from_into/v14.rs b/metadata/src/from_into/v14.rs index a324aa8953..dec3a4c566 100644 --- a/metadata/src/from_into/v14.rs +++ b/metadata/src/from_into/v14.rs @@ -3,15 +3,15 @@ // see LICENSE for license details. use super::TryFromError; -use crate::prelude::*; use crate::Metadata; -use borrow::ToOwned; -use fmt::Write; +use alloc::borrow::ToOwned; +use alloc::string::String; +use alloc::vec; +use alloc::vec::Vec; + use frame_metadata::{v14, v15}; use hashbrown::HashMap; use scale_info::TypeDef; -use string::String; -use vec::Vec; impl TryFrom for Metadata { type Error = TryFromError; @@ -374,8 +374,9 @@ fn generate_outer_error_enum_type( // Note: using the `format!` macro like in `let path = format!("{}Error", pallet.name);` // leads to linker errors about extern function `_Unwind_Resume` not being defined. - let mut path = String::new(); - write!(path, "{}Error", pallet.name).expect("Cannot panic, qed;"); + // let mut path = String::new(); + // write!(path, "{}Error", pallet.name).expect("Cannot panic, qed;"); + let path = alloc::format!("{}Error", pallet.name); let ty = error.ty.id.into(); Some(scale_info::Variant { diff --git a/metadata/src/from_into/v15.rs b/metadata/src/from_into/v15.rs index 5021da1b8d..37e4336543 100644 --- a/metadata/src/from_into/v15.rs +++ b/metadata/src/from_into/v15.rs @@ -3,7 +3,7 @@ // see LICENSE for license details. use super::TryFromError; -use crate::prelude::*; + use crate::utils::variant_index::VariantIndex; use crate::{ utils::ordered_map::OrderedMap, ArcStr, ConstantMetadata, ExtrinsicMetadata, Metadata, @@ -11,7 +11,7 @@ use crate::{ RuntimeApiMethodParamMetadata, SignedExtensionMetadata, StorageEntryMetadata, StorageEntryModifier, StorageEntryType, StorageHasher, StorageMetadata, }; -use borrow::ToOwned; +use alloc::borrow::ToOwned; use frame_metadata::v15; use hashbrown::HashMap; use scale_info::form::PortableForm; diff --git a/metadata/src/lib.rs b/metadata/src/lib.rs index ad2503235a..59a3ba484b 100644 --- a/metadata/src/lib.rs +++ b/metadata/src/lib.rs @@ -17,18 +17,18 @@ #![cfg_attr(not(feature = "std"), no_std)] #![deny(missing_docs)] +extern crate alloc; + mod from_into; -mod prelude; mod utils; +use alloc::string::String; +use alloc::sync::Arc; +use alloc::vec::Vec; use hashbrown::HashMap; -use prelude::*; use scale_info::{form::PortableForm, PortableRegistry, Variant}; -use string::String; -use sync::Arc; use utils::variant_index::VariantIndex; use utils::{ordered_map::OrderedMap, validation::outer_enum_hashes::OuterEnumHashes}; -use vec::Vec; type ArcStr = Arc; @@ -205,7 +205,7 @@ impl Metadata { // its name to ensure that every unique type has a unique path, too. if *visited_count > 1 { if let Some(name) = ty.ty.path.segments.last_mut() { - *name = format!("{name}{visited_count}"); + *name = alloc::format!("{name}{visited_count}"); } } } diff --git a/metadata/src/prelude.rs b/metadata/src/prelude.rs deleted file mode 100644 index 007bd44665..0000000000 --- a/metadata/src/prelude.rs +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2019-2023 Parity Technologies (UK) Ltd. -// This file is dual-licensed as Apache-2.0 or GPL-3.0. -// see LICENSE for license details. - -#[cfg(not(feature = "std"))] -extern crate alloc; - -use cfg_if::cfg_if; - -cfg_if! { - if #[cfg(feature = "std")] { - #[allow(unused)] - pub use std::{ - any, - borrow, - boxed, - cmp, - collections, - fmt, - format, - hash, - marker, - mem, - num, - ops, - string, - sync, - time, - vec, - rc, - iter, - }; - } else { - #[allow(unused)] - pub use alloc::{ - borrow, - boxed, - collections, - format, - string, - sync, - vec, - rc - }; - #[allow(unused)] - pub use core::{ - any, - cmp, - fmt, - hash, - marker, - mem, - num, - ops, - time, - iter, - }; - } -} diff --git a/metadata/src/utils/ordered_map.rs b/metadata/src/utils/ordered_map.rs index 8df2ade3a3..614c25cf65 100644 --- a/metadata/src/utils/ordered_map.rs +++ b/metadata/src/utils/ordered_map.rs @@ -2,9 +2,9 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::prelude::*; +use alloc::vec::Vec; +use core::mem; use hashbrown::HashMap; -use vec::Vec; /// A minimal ordered map to let one search for /// things by key or get the values in insert order. @@ -25,7 +25,7 @@ impl Default for OrderedMap { impl OrderedMap where - K: PartialEq + Eq + hash::Hash, + K: PartialEq + Eq + core::hash::Hash, { /// Create a new, empty [`OrderedMap`]. pub fn new() -> Self { @@ -80,8 +80,8 @@ where /// Get an item by its key. pub fn get_by_key(&self, key: &Q) -> Option<&V> where - K: borrow::Borrow, - Q: hash::Hash + Eq + ?Sized, + K: alloc::borrow::Borrow, + Q: core::hash::Hash + Eq + ?Sized, { self.map.get(key).and_then(|&v| self.values.get(v)) } @@ -109,7 +109,7 @@ where impl FromIterator<(K, V)> for OrderedMap where - K: PartialEq + Eq + hash::Hash, + K: PartialEq + Eq + core::hash::Hash, { fn from_iter>(iter: T) -> Self { let mut map = OrderedMap::new(); diff --git a/metadata/src/utils/retain.rs b/metadata/src/utils/retain.rs index 5e26bd2e83..a160609597 100644 --- a/metadata/src/utils/retain.rs +++ b/metadata/src/utils/retain.rs @@ -4,12 +4,11 @@ //! Utility functions to generate a subset of the metadata. -use crate::prelude::*; use crate::{ ExtrinsicMetadata, Metadata, OuterEnumsMetadata, PalletMetadataInner, RuntimeApiMetadataInner, StorageEntryType, }; -use collections::BTreeMap; +use alloc::collections::BTreeMap; use hashbrown::HashSet; use scale_info::TypeDef; diff --git a/metadata/src/utils/validation.rs b/metadata/src/utils/validation.rs index e36d05810d..2b1b1f5e33 100644 --- a/metadata/src/utils/validation.rs +++ b/metadata/src/utils/validation.rs @@ -4,15 +4,14 @@ //! Utility functions for metadata validation. -use crate::prelude::*; use crate::{ CustomMetadata, CustomValueMetadata, ExtrinsicMetadata, Metadata, PalletMetadata, RuntimeApiMetadata, RuntimeApiMethodMetadata, StorageEntryMetadata, StorageEntryType, }; +use alloc::vec::Vec; use hashbrown::HashMap; use outer_enum_hashes::OuterEnumHashes; use scale_info::{form::PortableForm, Field, PortableRegistry, TypeDef, TypeDefVariant, Variant}; -use vec::Vec; pub mod outer_enum_hashes; diff --git a/metadata/src/utils/variant_index.rs b/metadata/src/utils/variant_index.rs index 31aed098b6..9019aee3ab 100644 --- a/metadata/src/utils/variant_index.rs +++ b/metadata/src/utils/variant_index.rs @@ -2,11 +2,10 @@ // This file is dual-licensed as Apache-2.0 or GPL-3.0. // see LICENSE for license details. -use crate::prelude::*; -use borrow::ToOwned; +use alloc::borrow::ToOwned; +use alloc::string::String; use hashbrown::HashMap; use scale_info::{form::PortableForm, PortableRegistry, TypeDef, Variant}; -use string::String; /// Given some type ID and type registry, build a couple of /// indexes to look up variants by index or name. If the ID provided @@ -65,8 +64,8 @@ impl VariantIndex { types: &'a PortableRegistry, ) -> Option<&'a Variant> where - String: borrow::Borrow, - K: hash::Hash + Eq + ?Sized, + String: alloc::borrow::Borrow, + K: core::hash::Hash + Eq + ?Sized, { let pos = *self.by_name.get(name)?; let variants = Self::get(variant_id, types)?; diff --git a/testing/no-std-tests/Cargo.lock b/testing/no-std-tests/Cargo.lock index e1d9e0d46e..277d009358 100644 --- a/testing/no-std-tests/Cargo.lock +++ b/testing/no-std-tests/Cargo.lock @@ -371,7 +371,6 @@ dependencies = [ name = "subxt-metadata" version = "0.34.0" dependencies = [ - "cfg-if", "derive_more", "frame-metadata", "hashbrown",