Skip to content

Commit

Permalink
Removes std mod and moves imports into lib.
Browse files Browse the repository at this point in the history
  • Loading branch information
claravanstaden authored and claravanstaden committed Dec 14, 2022
1 parent b58448c commit d776326
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 38 deletions.
2 changes: 1 addition & 1 deletion ssz-rs/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions ssz-rs/src/bitlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -208,7 +208,6 @@ impl<const N: usize> FromIterator<bool> for Bitlist<N> {

#[cfg(test)]
mod tests {
use std::hash::Hash;
use super::*;
use crate::serialize;

Expand Down
2 changes: 1 addition & 1 deletion ssz-rs/src/bitvector.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
2 changes: 1 addition & 1 deletion ssz-rs/src/boolean.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion ssz-rs/src/de.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::ser::BYTES_PER_LENGTH_OFFSET;
use crate::std::*;
use crate::lib::*;
use crate::SimpleSerialize;

#[derive(Debug)]
Expand Down
27 changes: 25 additions & 2 deletions ssz-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions ssz-rs/src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -301,7 +301,7 @@ pub struct IterMut<'a, T, const N: usize>
where
T: SimpleSerialize,
{
inner: Enumerate<crate::std::IterMut<'a, T>>,
inner: Enumerate<crate::lib::IterMut<'a, T>>,
cache: &'a mut MerkleCache,
}

Expand Down
4 changes: 2 additions & 2 deletions ssz-rs/src/merkleization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion ssz-rs/src/merkleization/node.rs
Original file line number Diff line number Diff line change
@@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion ssz-rs/src/ser.rs
Original file line number Diff line number Diff line change
@@ -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!
Expand Down
21 changes: 0 additions & 21 deletions ssz-rs/src/std.rs

This file was deleted.

2 changes: 1 addition & 1 deletion ssz-rs/src/uint.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion ssz-rs/src/union.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion ssz-rs/src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d776326

Please sign in to comment.