diff --git a/ssz-rs/src/array.rs b/ssz-rs/src/array.rs index 5b8bc15e..a3dec8be 100644 --- a/ssz-rs/src/array.rs +++ b/ssz-rs/src/array.rs @@ -8,7 +8,7 @@ use crate::merkleization::{ merkleize, pack, MerkleizationError, Merkleized, Node, BYTES_PER_CHUNK, }; use crate::ser::{serialize_composite, Serialize, SerializeError}; -use crate::std::*; +use crate::lib::*; use crate::{SimpleSerialize, Sized}; macro_rules! define_ssz_for_array_of_size { diff --git a/ssz-rs/src/bitlist.rs b/ssz-rs/src/bitlist.rs index 41ce27be..03298f0a 100644 --- a/ssz-rs/src/bitlist.rs +++ b/ssz-rs/src/bitlist.rs @@ -3,7 +3,7 @@ use crate::merkleization::{ merkleize, mix_in_length, pack_bytes, MerkleizationError, Merkleized, Node, }; use crate::ser::{Serialize, SerializeError}; -use crate::std::*; +use crate::lib::*; use crate::{SimpleSerialize, Sized}; use bitvec::prelude::{BitVec, Lsb0}; @@ -208,7 +208,6 @@ impl FromIterator for Bitlist { #[cfg(test)] mod tests { - use std::hash::Hash; use super::*; use crate::serialize; diff --git a/ssz-rs/src/bitvector.rs b/ssz-rs/src/bitvector.rs index e2eadfac..fee67f23 100644 --- a/ssz-rs/src/bitvector.rs +++ b/ssz-rs/src/bitvector.rs @@ -1,7 +1,7 @@ use crate::de::{Deserialize, DeserializeError}; use crate::merkleization::{merkleize, pack_bytes, MerkleizationError, Merkleized, Node}; use crate::ser::{Serialize, SerializeError}; -use crate::std::*; +use crate::lib::*; use crate::{SimpleSerialize, Sized}; use bitvec::field::BitField; use bitvec::prelude::{BitVec, Lsb0}; diff --git a/ssz-rs/src/boolean.rs b/ssz-rs/src/boolean.rs index 1c2ae4b7..b71b43db 100644 --- a/ssz-rs/src/boolean.rs +++ b/ssz-rs/src/boolean.rs @@ -1,7 +1,7 @@ use crate::de::{Deserialize, DeserializeError}; use crate::merkleization::{MerkleizationError, Merkleized, Node}; use crate::ser::{Serialize, SerializeError}; -use crate::std::*; +use crate::lib::*; use crate::{SimpleSerialize, Sized}; impl Sized for bool { diff --git a/ssz-rs/src/de.rs b/ssz-rs/src/de.rs index fda8f0f9..02970e57 100644 --- a/ssz-rs/src/de.rs +++ b/ssz-rs/src/de.rs @@ -1,5 +1,5 @@ use crate::ser::BYTES_PER_LENGTH_OFFSET; -use crate::std::*; +use crate::lib::*; use crate::SimpleSerialize; #[derive(Debug)] diff --git a/ssz-rs/src/lib.rs b/ssz-rs/src/lib.rs index 50cc65b7..ca0cc7aa 100644 --- a/ssz-rs/src/lib.rs +++ b/ssz-rs/src/lib.rs @@ -14,12 +14,10 @@ mod merkleization; mod ser; #[cfg(feature = "serde")] mod serde_test; -mod std; mod uint; mod union; mod vector; -use crate::std::*; pub use bitlist::Bitlist; pub use bitvector::Bitvector; pub use de::{Deserialize, DeserializeError}; @@ -28,6 +26,31 @@ pub use merkleization::{Context as MerkleizationContext, MerkleizationError, Mer pub use ser::{Serialize, SerializeError}; pub use uint::U256; pub use vector::Vector; +use crate::lib::*; + +mod lib { + mod core { + #[cfg(not(feature = "std"))] + pub use core::*; + #[cfg(feature = "std")] + pub use std::*; + } + + pub use self::core::{any, cmp, iter, slice}; + + pub use self::cmp::Ordering; + pub use self::core::array::TryFromSliceError; + pub use self::core::fmt::{self, Debug, Display, Formatter}; + pub use self::core::ops::{Deref, DerefMut, Index, IndexMut}; + pub use self::core::slice::{IterMut, SliceIndex}; + pub use self::iter::Enumerate; + + #[cfg(not(feature = "std"))] + pub use alloc::{vec, vec::Vec}; + + #[cfg(feature = "std")] + pub use std::vec::Vec; +} /// `Sized` is a trait for types that can /// provide sizing information relevant for the SSZ spec. diff --git a/ssz-rs/src/list.rs b/ssz-rs/src/list.rs index da7929e8..e389c902 100644 --- a/ssz-rs/src/list.rs +++ b/ssz-rs/src/list.rs @@ -4,7 +4,7 @@ use crate::merkleization::{ BYTES_PER_CHUNK, }; use crate::ser::{serialize_composite, Serialize, SerializeError}; -use crate::std::*; +use crate::lib::*; use crate::{SimpleSerialize, Sized}; #[cfg(feature = "serde")] use serde::ser::SerializeSeq; @@ -301,7 +301,7 @@ pub struct IterMut<'a, T, const N: usize> where T: SimpleSerialize, { - inner: Enumerate>, + inner: Enumerate>, cache: &'a mut MerkleCache, } diff --git a/ssz-rs/src/merkleization/mod.rs b/ssz-rs/src/merkleization/mod.rs index 7e59b7c2..9cb28413 100644 --- a/ssz-rs/src/merkleization/mod.rs +++ b/ssz-rs/src/merkleization/mod.rs @@ -3,7 +3,7 @@ mod node; mod proofs; use crate::ser::Serialize; -use crate::std::*; +use crate::lib::*; use lazy_static::lazy_static; use sha2::{Digest, Sha256}; @@ -67,7 +67,7 @@ where { let mut buffer = vec![]; for value in values { - value.serialize(&mut buffer); + value.serialize(&mut buffer)?; } pack_bytes(&mut buffer); Ok(buffer) diff --git a/ssz-rs/src/merkleization/node.rs b/ssz-rs/src/merkleization/node.rs index 4ef7631e..2eab8af4 100644 --- a/ssz-rs/src/merkleization/node.rs +++ b/ssz-rs/src/merkleization/node.rs @@ -1,5 +1,5 @@ use crate::prelude::*; -use crate::std::*; +use crate::lib::*; #[derive(Default, Clone, Copy, PartialEq, Eq, SimpleSerialize)] pub struct Node(pub(crate) [u8; 32]); diff --git a/ssz-rs/src/ser.rs b/ssz-rs/src/ser.rs index ab6473b2..4c60a919 100644 --- a/ssz-rs/src/ser.rs +++ b/ssz-rs/src/ser.rs @@ -1,4 +1,4 @@ -use crate::std::*; +use crate::lib::*; use crate::SimpleSerialize; // NOTE: if this is changed, go change in `ssz_derive` as well! diff --git a/ssz-rs/src/std.rs b/ssz-rs/src/std.rs deleted file mode 100644 index ab8bb5c7..00000000 --- a/ssz-rs/src/std.rs +++ /dev/null @@ -1,21 +0,0 @@ -mod core { - #[cfg(not(feature = "std"))] - pub use core::*; - #[cfg(feature = "std")] - pub use std::*; -} - -pub use self::core::{any, cmp, iter, slice}; - -pub use self::cmp::Ordering; -pub use self::core::array::TryFromSliceError; -pub use self::core::fmt::{self, Debug, Display, Formatter}; -pub use self::core::ops::{Deref, DerefMut, Index, IndexMut}; -pub use self::core::slice::{IterMut, SliceIndex}; -pub use self::iter::Enumerate; - -#[cfg(not(feature = "std"))] -pub use alloc::{vec, vec::Vec}; - -#[cfg(feature = "std")] -pub use std::vec::Vec; diff --git a/ssz-rs/src/uint.rs b/ssz-rs/src/uint.rs index 30552687..2cb24ed3 100644 --- a/ssz-rs/src/uint.rs +++ b/ssz-rs/src/uint.rs @@ -1,7 +1,7 @@ use crate::de::{Deserialize, DeserializeError}; use crate::merkleization::{pack_bytes, MerkleizationError, Merkleized, Node}; use crate::ser::{Serialize, SerializeError}; -use crate::std::*; +use crate::lib::*; use crate::{SimpleSerialize, Sized}; use num_bigint::BigUint; diff --git a/ssz-rs/src/union.rs b/ssz-rs/src/union.rs index 7efa24a1..8313558b 100644 --- a/ssz-rs/src/union.rs +++ b/ssz-rs/src/union.rs @@ -1,7 +1,7 @@ use crate::de::{Deserialize, DeserializeError}; use crate::merkleization::{mix_in_selector, MerkleizationError, Merkleized, Node}; use crate::ser::{Serialize, SerializeError}; -use crate::std::*; +use crate::lib::*; use crate::{SimpleSerialize, Sized}; /// `SimpleSerialize` is implemented for `Option` as a convenience diff --git a/ssz-rs/src/vector.rs b/ssz-rs/src/vector.rs index 602f6e1f..04bdc7cc 100644 --- a/ssz-rs/src/vector.rs +++ b/ssz-rs/src/vector.rs @@ -3,7 +3,7 @@ use crate::merkleization::{ merkleize, pack, MerkleCache, MerkleizationError, Merkleized, Node, BYTES_PER_CHUNK, }; use crate::ser::{serialize_composite, Serialize}; -use crate::std::*; +use crate::lib::*; use crate::{SerializeError, SimpleSerialize, Sized}; #[cfg(feature = "serde")] use serde::ser::SerializeSeq;