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
@@ -17,9 +17,10 @@
//! Infinite precision unsigned integer for substrate runtime.
use alloc::{vec, vec::Vec};
use codec::{Decode, Encode};
use core::{cell::RefCell, cmp::Ordering, ops};
use num_traits::{One, Zero};
use sp_std::{cell::RefCell, cmp::Ordering, ops, prelude::*, vec};
// A sensible value for this would be half of the dword size of the host machine. Since the
// runtime is compiled to 32bit webassembly, using 32 and 64 for single and double respectively
@@ -35,7 +36,7 @@ const SHIFT: usize = 32;
const B: Double = Single::max_value() as Double + 1;
static_assertions::const_assert!(
sp_std::mem::size_of::<Double>() - sp_std::mem::size_of::<Single>() == SHIFT / 8
core::mem::size_of::<Double>() - core::mem::size_of::<Single>() == SHIFT / 8
);
/// Splits a [`Double`] limb number into a tuple of two [`Single`] limb numbers.
@@ -438,9 +439,9 @@ impl BigUint {
}
}
impl sp_std::fmt::Debug for BigUint {
impl core::fmt::Debug for BigUint {
#[cfg(feature = "std")]
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,
"BigUint {{ {:?} ({:?})}}",
@@ -450,7 +451,7 @@ impl sp_std::fmt::Debug for BigUint {
}
#[cfg(not(feature = "std"))]
fn fmt(&self, _: &mut sp_std::fmt::Formatter<'_>) -> sp_std::fmt::Result {
fn fmt(&self, _: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
Ok(())
}
}
@@ -26,17 +26,16 @@ use crate::{
PerThing, Perbill, Rounding, SignedRounding,
};
use codec::{CompactAs, Decode, Encode};
use sp_std::{
use core::{
fmt::Debug,
ops::{self, Add, Div, Mul, Sub},
prelude::*,
};
#[cfg(feature = "serde")]
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
#[cfg(all(not(feature = "std"), feature = "serde"))]
use sp_std::alloc::string::{String, ToString};
use alloc::string::{String, ToString};
/// Integer types that can be used to interact with `FixedPointNumber` implementations.
pub trait FixedPointOperand:
@@ -899,9 +898,9 @@ macro_rules! implement_fixed {
}
}
impl sp_std::fmt::Debug for $name {
impl ::core::fmt::Debug for $name {
#[cfg(feature = "std")]
fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
let integral = {
let int = self.0 / Self::accuracy();
let signum_for_zero = if int == 0 && self.is_negative() { "-" } else { "" };
@@ -917,7 +916,7 @@ macro_rules! implement_fixed {
}
#[cfg(not(feature = "std"))]
fn fmt(&self, _: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
fn fmt(&self, _: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
Ok(())
}
}
@@ -933,13 +932,13 @@ macro_rules! implement_fixed {
}
}
impl sp_std::fmt::Display for $name {
fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
impl ::core::fmt::Display for $name {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}", self.0)
}
}
impl sp_std::str::FromStr for $name {
impl ::core::str::FromStr for $name {
type Err = &'static str;
fn from_str(s: &str) -> Result<Self, Self::Err> {
@@ -969,7 +968,7 @@ macro_rules! implement_fixed {
where
D: Deserializer<'de>,
{
use sp_std::str::FromStr;
use ::core::str::FromStr;
let s = String::deserialize(deserializer)?;
$name::from_str(&s).map_err(de::Error::custom)
}
+5 -2
View File
@@ -19,6 +19,8 @@
#![cfg_attr(not(feature = "std"), no_std)]
extern crate alloc;
/// Copied from `sp-runtime` and documented there.
#[macro_export]
macro_rules! assert_eq_error_rate {
@@ -49,7 +51,8 @@ pub use per_things::{
};
pub use rational::{MultiplyRational, Rational128, RationalInfinite};
use sp_std::{cmp::Ordering, fmt::Debug, prelude::*};
use alloc::vec::Vec;
use core::{cmp::Ordering, fmt::Debug};
use traits::{BaseArithmetic, One, SaturatedConversion, Unsigned, Zero};
use codec::{Decode, Encode, MaxEncodedLen};
@@ -429,7 +432,7 @@ mod normalize_tests {
mod threshold_compare_tests {
use super::*;
use crate::traits::Saturating;
use sp_std::cmp::Ordering;
use core::cmp::Ordering;
#[test]
fn epsilon_ord_works() {
@@ -23,12 +23,11 @@ use crate::traits::{
Saturating, UniqueSaturatedInto, Unsigned, Zero,
};
use codec::{CompactAs, Encode};
use num_traits::{Pow, SaturatingAdd, SaturatingSub};
use sp_std::{
use core::{
fmt, ops,
ops::{Add, Sub},
prelude::*,
};
use num_traits::{Pow, SaturatingAdd, SaturatingSub};
/// Get the inner type of a `PerThing`.
pub type InnerOf<P> = <P as PerThing>::Inner;
@@ -414,7 +413,7 @@ pub trait PerThing:
}
/// The rounding method to use for unsigned quantities.
#[derive(Copy, Clone, sp_std::fmt::Debug)]
#[derive(Copy, Clone, core::fmt::Debug)]
pub enum Rounding {
// Towards infinity.
Up,
@@ -427,7 +426,7 @@ pub enum Rounding {
}
/// The rounding method to use.
#[derive(Copy, Clone, sp_std::fmt::Debug)]
#[derive(Copy, Clone, core::fmt::Debug)]
pub enum SignedRounding {
// Towards positive infinity.
High,
@@ -580,8 +579,8 @@ macro_rules! implement_per_thing {
}
#[cfg(feature = "std")]
impl sp_std::fmt::Debug for $name {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
impl core::fmt::Debug for $name {
fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {
if $max == <$type>::max_value() {
// Not a power of ten: show as N/D and approx %
let pc = (self.0 as f64) / (self.0 as f64) * 100f64;
@@ -606,8 +605,8 @@ macro_rules! implement_per_thing {
}
#[cfg(not(feature = "std"))]
impl sp_std::fmt::Debug for $name {
fn fmt(&self, fmt: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
impl core::fmt::Debug for $name {
fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {
if $max == <$type>::max_value() {
// Not a power of ten: show as N/D and approx %
write!(fmt, "{}/{}", self.0, $max)
@@ -16,8 +16,8 @@
// limitations under the License.
use crate::{biguint::BigUint, helpers_128bit, Rounding};
use core::cmp::Ordering;
use num_traits::{Bounded, One, Zero};
use sp_std::{cmp::Ordering, prelude::*};
/// A wrapper for any rational number with infinitely large numerator and denominator.
///
@@ -92,15 +92,15 @@ impl From<Rational128> for RationalInfinite {
pub struct Rational128(u128, u128);
#[cfg(feature = "std")]
impl sp_std::fmt::Debug for Rational128 {
fn fmt(&self, f: &mut sp_std::fmt::Formatter<'_>) -> sp_std::fmt::Result {
impl core::fmt::Debug for Rational128 {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "Rational128({} / {} ≈ {:.8})", self.0, self.1, self.0 as f64 / self.1 as f64)
}
}
#[cfg(not(feature = "std"))]
impl sp_std::fmt::Debug for Rational128 {
fn fmt(&self, f: &mut sp_std::fmt::Formatter<'_>) -> sp_std::fmt::Result {
impl core::fmt::Debug for Rational128 {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "Rational128({} / {})", self.0, self.1)
}
}