From 3bd29909d385f997785d4f6dfbca0da75f909495 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Mon, 23 Jan 2023 12:15:05 +0100 Subject: [PATCH] misc cleanups --- ssz-rs/src/error.rs | 6 +++--- ssz-rs/src/lib.rs | 4 ++-- ssz-rs/src/list.rs | 6 +++--- ssz-rs/src/merkleization/mod.rs | 10 ++-------- ssz-rs/src/ser.rs | 7 ++----- ssz-rs/src/vector.rs | 4 ++-- 6 files changed, 14 insertions(+), 23 deletions(-) diff --git a/ssz-rs/src/error.rs b/ssz-rs/src/error.rs index 38082d7d..573b0c57 100644 --- a/ssz-rs/src/error.rs +++ b/ssz-rs/src/error.rs @@ -6,9 +6,9 @@ use crate::ser::SerializeError; // Top-level error to wrap all child errors in crate #[derive(Debug)] pub enum Error { - Serialize(/*#[from]*/ SerializeError), - Deserialize(/*#[from]*/ DeserializeError), - Merkleization(/*#[from]*/ MerkleizationError), + Serialize(SerializeError), + Deserialize(DeserializeError), + Merkleization(MerkleizationError), } impl From for Error { diff --git a/ssz-rs/src/lib.rs b/ssz-rs/src/lib.rs index d109c2c8..b6c2a692 100644 --- a/ssz-rs/src/lib.rs +++ b/ssz-rs/src/lib.rs @@ -39,11 +39,11 @@ mod lib { pub use std::*; } - pub use self::core::{any, cmp, iter, slice}; + pub use self::core::{any, cmp, fmt, 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::fmt::{Debug, Display, Formatter}; pub use self::core::ops::{Deref, DerefMut, Index, IndexMut}; pub use self::core::slice::{IterMut, SliceIndex}; pub use self::iter::Enumerate; diff --git a/ssz-rs/src/list.rs b/ssz-rs/src/list.rs index c8495149..69256c75 100644 --- a/ssz-rs/src/list.rs +++ b/ssz-rs/src/list.rs @@ -8,9 +8,9 @@ use crate::merkleization::{ use crate::ser::{serialize_composite, Serialize, SerializeError}; use crate::{SimpleSerialize, Sized}; #[cfg(feature = "serde")] -use core::marker::PhantomData; -#[cfg(feature = "serde")] use serde::ser::SerializeSeq; +#[cfg(feature = "serde")] +use std::marker::PhantomData; /// A homogenous collection of a variable number of values. #[derive(Clone, Default)] @@ -287,7 +287,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 cd8796ea..050e4b8a 100644 --- a/ssz-rs/src/merkleization/mod.rs +++ b/ssz-rs/src/merkleization/mod.rs @@ -19,9 +19,7 @@ pub trait Merkleized { #[derive(Debug)] pub enum MerkleizationError { - // #[error("failed to serialize value: {0}")] - SerializationError(/*#[from]*/ SerializeError), - // #[error("cannot merkleize data that exceeds the declared limit {0}")] + SerializationError(SerializeError), InputExceedsLimit(usize), } @@ -33,15 +31,11 @@ impl From for MerkleizationError { impl Display for MerkleizationError { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - write!(f, "the value could not be merkleized: ")?; match self { Self::SerializationError(err) => { write!(f, "failed to serialize value: {err}") } - Self::InputExceedsLimit(size) => write!( - f, - "cannot merkleize data that exceeds the declared limit: {size}", - ), + Self::InputExceedsLimit(size) => write!(f, "data exceeds the declared limit {size}"), } } } diff --git a/ssz-rs/src/ser.rs b/ssz-rs/src/ser.rs index f23b8e2c..352286f7 100644 --- a/ssz-rs/src/ser.rs +++ b/ssz-rs/src/ser.rs @@ -8,12 +8,9 @@ const MAXIMUM_LENGTH: u64 = 2u64.pow((8 * BYTES_PER_LENGTH_OFFSET) as u32); #[derive(Debug)] pub enum SerializeError { - // #[error("the encoded length is {0} which exceeds the maximum length {MAXIMUM_LENGTH}")] MaximumEncodedLengthExceeded(usize), - // #[error("invalid instance: {0}")] - InvalidInstance(/*#[from]*/ InstanceError), - // #[error("invalid type: {0}")] - InvalidType(/*#[from]*/ TypeError), + InvalidInstance(InstanceError), + InvalidType(TypeError), } impl From for SerializeError { diff --git a/ssz-rs/src/vector.rs b/ssz-rs/src/vector.rs index b821ab83..a2ba50c4 100644 --- a/ssz-rs/src/vector.rs +++ b/ssz-rs/src/vector.rs @@ -7,9 +7,9 @@ use crate::merkleization::{ use crate::ser::{serialize_composite, Serialize, SerializeError}; use crate::{SimpleSerialize, Sized}; #[cfg(feature = "serde")] -use core::marker::PhantomData; -#[cfg(feature = "serde")] use serde::ser::SerializeSeq; +#[cfg(feature = "serde")] +use std::marker::PhantomData; /// A homogenous collection of a fixed number of values. /// NOTE: a `Vector` of length `0` is illegal.