Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
Remove sp-std for core/alloc
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelburnham committed Oct 18, 2021
1 parent e8694e5 commit 03868f8
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 32 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "sp-ipld"
version = "0.1.2"
version = "0.2.0"
edition = "2018"
authors = ["Samuel Burnham <sam@yatima.io>", "John Burnham <john@yatima.io>"]
license = "MIT"
Expand All @@ -18,7 +18,6 @@ dag-cbor = ["multibase", "byteorder", "sp-multihash"]
std = []

[dependencies]
sp-std = { version = "3", default-features = false }
byteorder = { version = "1", default-features = false, optional = true }
unsigned-varint = { version = "0.7.0", default-features = false }
multibase = { version = "0.9.1", default-features = false, optional = true }
Expand Down
8 changes: 5 additions & 3 deletions src/codec.rs
@@ -1,11 +1,13 @@
use bytecursor::ByteCursor;
use sp_cid::Cid;

use alloc::string::String;
use sp_std::{
use alloc::{
string::String,
vec::Vec
};
use core::{
convert::TryFrom,
ops::Deref,
vec::Vec,
};

pub struct UnsupportedCodec(pub u64);
Expand Down
4 changes: 2 additions & 2 deletions src/dag_cbor.rs
Expand Up @@ -14,7 +14,7 @@ use sp_multihash::{
MultihashDigest,
};

use sp_std::convert::TryFrom;
use core::convert::TryFrom;

pub mod decode;
pub mod encode;
Expand Down Expand Up @@ -64,7 +64,7 @@ pub mod tests {
Gen,
};

use sp_std::collections::btree_map::BTreeMap;
use alloc::collections::btree_map::BTreeMap;

fn encode_decode_id<T: DagCbor + PartialEq<T> + Clone>(value: T) -> bool {
let mut bc = ByteCursor::new(Vec::new());
Expand Down
10 changes: 4 additions & 6 deletions src/dag_cbor/decode.rs
Expand Up @@ -10,25 +10,23 @@ use crate::{

use alloc::{
borrow::ToOwned,
format,
boxed::Box,
collections::btree_map::BTreeMap,
string::{
String,
ToString,
},
sync::Arc,
vec,
vec::Vec,
};
use byteorder::{
BigEndian,
ByteOrder,
};

use sp_std::{
use core::{
any::type_name,
boxed::Box,
collections::btree_map::BTreeMap,
convert::TryFrom,
vec::Vec,
};

use bytecursor::{
Expand Down
9 changes: 6 additions & 3 deletions src/dag_cbor/encode.rs
Expand Up @@ -16,13 +16,16 @@ use byteorder::{
ByteOrder,
};
use sp_cid::Cid;
use sp_std::{
use alloc::{
collections::btree_map::BTreeMap,
vec::Vec,
};

use core::{
convert::TryFrom,
mem,
ops::Deref,
vec::Vec,
};
};

/// # Errors
///
Expand Down
4 changes: 2 additions & 2 deletions src/dag_json.rs
Expand Up @@ -83,7 +83,7 @@ pub fn from_dag_json_string(s: String) -> Result<Ipld, String> {
/// # Errors
/// Will return `Err` if there was an error converting the IPLD to JSON.
pub fn to_dag_json_string(ipld: Ipld) -> Result<String, String> {
let mut w = ByteCursor::new(sp_std::vec![]);
let mut w = ByteCursor::new(vec![]);
codec::encode(&ipld, &mut w).map_err(|e| e.to_string())?;
Ok(String::from(String::from_utf8_lossy(&w.into_inner())))
}
Expand All @@ -99,7 +99,7 @@ pub mod tests {
Gen,
};

use sp_std::collections::btree_map::BTreeMap;
use alloc::collections::btree_map::BTreeMap;

fn encode_decode_id<
T: Encode<DagJsonCodec> + Decode<DagJsonCodec> + PartialEq<T> + Clone,
Expand Down
4 changes: 2 additions & 2 deletions src/dag_json/codec.rs
Expand Up @@ -15,11 +15,11 @@ use serde::{
};
use serde_json::Error;
use sp_cid::Cid;
use sp_std::{
use alloc::{
collections::btree_map::BTreeMap,
fmt,
vec::Vec,
};
use core::fmt;

const SPECIAL_KEY: &str = "/";

Expand Down
15 changes: 6 additions & 9 deletions src/ipld.rs
@@ -1,11 +1,9 @@
use alloc::{
borrow::ToOwned,
string::String,
vec,
};
use sp_cid::Cid;
use sp_std::{
self,
use alloc::{
borrow::ToOwned,
boxed::Box,
collections::btree_map::BTreeMap,
vec::Vec,
Expand Down Expand Up @@ -34,8 +32,8 @@ pub enum Ipld {
Link(Cid),
}

impl sp_std::fmt::Debug for Ipld {
fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
impl core::fmt::Debug for Ipld {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
use Ipld::*;
match self {
Null => write!(f, "null"),
Expand All @@ -61,7 +59,7 @@ impl Ipld {
pub fn references<E: Extend<Cid>>(&self, set: &mut E) {
for ipld in self.iter() {
if let Ipld::Link(cid) = ipld {
set.extend(sp_std::iter::once(cid.to_owned()));
set.extend(core::iter::once(cid.to_owned()));
}
}
}
Expand Down Expand Up @@ -113,7 +111,6 @@ pub struct IpldIter<'a> {
pub mod tests {
use super::*;
use crate::rand::Rng;
use alloc::vec;
use quickcheck::{
Arbitrary,
Gen,
Expand All @@ -122,7 +119,7 @@ pub mod tests {
Code,
MultihashDigest,
};
use sp_std::boxed::Box;
use alloc::boxed::Box;

pub(crate) fn arbitrary_cid(g: &mut Gen) -> Cid {
let mut bytes: [u8; 32] = [0; 32];
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Expand Up @@ -5,8 +5,9 @@
clippy::missing_safety_doc
)]
#![cfg_attr(not(any(feature = "std", test)), no_std)]

#[macro_use]
extern crate alloc;
extern crate sp_std;

#[cfg(test)]
extern crate quickcheck;
Expand Down

0 comments on commit 03868f8

Please sign in to comment.