Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sp-std removal from substrate/primitives #3274

Merged
merged 12 commits into from
Mar 18, 2024
31 changes: 0 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions substrate/primitives/arithmetic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ num-traits = { version = "0.2.17", default-features = false }
scale-info = { version = "2.10.0", default-features = false, features = ["derive"] }
serde = { features = ["alloc", "derive"], optional = true, workspace = true }
static_assertions = "1.1.0"
sp-std = { path = "../std", default-features = false }

[dev-dependencies]
criterion = "0.4.0"
Expand All @@ -42,7 +41,6 @@ std = [
"scale-info/std",
"serde/std",
"sp-crypto-hashing/std",
"sp-std/std",
]
# Serde support without relying on std features.
serde = ["dep:serde", "scale-info/serde"]
Expand Down
11 changes: 6 additions & 5 deletions substrate/primitives/arithmetic/src/biguint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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 {{ {:?} ({:?})}}",
Expand All @@ -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(())
}
}
Expand Down
19 changes: 9 additions & 10 deletions substrate/primitives/arithmetic/src/fixed_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 { "" };
Expand All @@ -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(())
}
}
Expand All @@ -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> {
Expand Down Expand Up @@ -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)
}
Expand Down
Loading
Loading