From f035b1faf9fdb4c20f75f7f54a0187bacb2d8b7d Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Tue, 9 May 2023 16:26:13 +0200 Subject: [PATCH] chore: move error module to integer list (#2614) --- crates/primitives/src/error.rs | 13 ------------- crates/primitives/src/integer_list.rs | 26 +++++++++++++++++--------- crates/primitives/src/lib.rs | 1 - 3 files changed, 17 insertions(+), 23 deletions(-) delete mode 100644 crates/primitives/src/error.rs diff --git a/crates/primitives/src/error.rs b/crates/primitives/src/error.rs deleted file mode 100644 index 1918399165..0000000000 --- a/crates/primitives/src/error.rs +++ /dev/null @@ -1,13 +0,0 @@ -//! Primitive errors -use thiserror::Error; - -/// Primitives error type. -#[derive(Debug, Error)] -pub enum Error { - /// The provided input is invalid. - #[error("The provided input is invalid.")] - InvalidInput, - /// Failed to deserialize data into type. - #[error("Failed to deserialize data into type.")] - FailedDeserialize, -} diff --git a/crates/primitives/src/integer_list.rs b/crates/primitives/src/integer_list.rs index 78443c609c..77f12a953b 100644 --- a/crates/primitives/src/integer_list.rs +++ b/crates/primitives/src/integer_list.rs @@ -1,4 +1,3 @@ -use crate::error::Error; use serde::{ de::{Unexpected, Visitor}, Deserialize, Deserializer, Serialize, Serializer, @@ -24,8 +23,8 @@ impl IntegerList { /// [`sucds::EliasFano`] restricts its compilation to 64bits. /// /// List should be pre-sorted and not empty. - pub fn new>(list: T) -> Result { - Ok(Self(EliasFano::from_ints(list.as_ref()).map_err(|_| Error::InvalidInput)?)) + pub fn new>(list: T) -> Result { + Ok(Self(EliasFano::from_ints(list.as_ref()).map_err(|_| EliasFanoError::InvalidInput)?)) } /// Serializes a [`IntegerList`] into a sequence of bytes. @@ -44,8 +43,8 @@ impl IntegerList { } /// Deserializes a sequence of bytes into a proper [`IntegerList`]. - pub fn from_bytes(data: &[u8]) -> Result { - Ok(Self(EliasFano::deserialize_from(data).map_err(|_| Error::FailedDeserialize)?)) + pub fn from_bytes(data: &[u8]) -> Result { + Ok(Self(EliasFano::deserialize_from(data).map_err(|_| EliasFanoError::FailedDeserialize)?)) } } @@ -111,6 +110,17 @@ impl<'a> Arbitrary<'a> for IntegerList { } } +/// Primitives error type. +#[derive(Debug, thiserror::Error)] +pub enum EliasFanoError { + /// The provided input is invalid. + #[error("The provided input is invalid.")] + InvalidInput, + /// Failed to deserialize data into type. + #[error("Failed to deserialize data into type.")] + FailedDeserialize, +} + #[cfg(test)] mod test { use super::*; @@ -118,10 +128,8 @@ mod test { #[test] fn test_integer_list() { let original_list = [1, 2, 3]; - let ef_list = IntegerList::new(original_list).unwrap(); - - assert!(ef_list.iter(0).collect::>() == original_list); + assert_eq!(ef_list.iter(0).collect::>(), original_list); } #[test] @@ -130,6 +138,6 @@ mod test { let ef_list = IntegerList::new(original_list).unwrap(); let blist = ef_list.to_bytes(); - assert!(IntegerList::from_bytes(&blist).unwrap() == ef_list) + assert_eq!(IntegerList::from_bytes(&blist).unwrap(), ef_list) } } diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index d80dafb523..d4c29974bd 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -18,7 +18,6 @@ mod chain; mod checkpoints; pub mod constants; pub mod contract; -mod error; pub mod filter; mod forkid; mod genesis;