From 0a1fb03757a3ecba86f2f72a514e6b35c9a1896a Mon Sep 17 00:00:00 2001 From: Malik672 Date: Thu, 11 Jan 2024 13:05:00 +0100 Subject: [PATCH 1/5] remove redendant code + 0.9.0 --- src/error.rs | 15 +-------------- src/utils/sorted_insert.rs | 4 ++-- src/utils/sqrt.rs | 2 +- 3 files changed, 4 insertions(+), 17 deletions(-) diff --git a/src/error.rs b/src/error.rs index b7f9613..749df38 100644 --- a/src/error.rs +++ b/src/error.rs @@ -2,11 +2,6 @@ use crate::prelude::*; #[derive(Debug, Error)] pub enum Error { - #[error("{field} must be greater than 0")] - ChainIdError { field: &'static str }, - - #[error(transparent)] - ParseError(#[from] std::num::ParseIntError), #[error("Chain IDs do not match: {0} and {1}")] ChainIdMismatch(u32, u32), @@ -17,18 +12,10 @@ pub enum Error { #[error("amount has exceeded MAX_UINT256")] MaxUint, - #[error("Error creating: {0}")] - CreationError(String), - - #[error("Can't get the fractional amount: {0}")] - CreateFractionalError(String), - #[error("not equal: {0}")] NotEqual(String), - #[error("Denominator is 0")] - DenominatorIsZero, - + //Custo #[error("incorrect: {0}")] Incorrect(String), } diff --git a/src/utils/sorted_insert.rs b/src/utils/sorted_insert.rs index 7bbb772..4468946 100644 --- a/src/utils/sorted_insert.rs +++ b/src/utils/sorted_insert.rs @@ -9,11 +9,11 @@ pub fn sorted_insert( comparator: fn(&T, &T) -> Ordering, ) -> Result, Error> { if max_size == 0 { - return Err(Error::Incorrect("MAX_SIZE_ZERO".to_owned())); + return Err(Error::Incorrect("max_size can't be equals to zero".to_owned())); } if items.len() > max_size { - return Err(Error::Incorrect("ITEMS_SIZE".to_owned())); + return Err(Error::Incorrect("items_size has to greater than max_size".to_string())); } let removed_item = if items.len() == max_size { diff --git a/src/utils/sqrt.rs b/src/utils/sqrt.rs index da9260b..aa02e20 100644 --- a/src/utils/sqrt.rs +++ b/src/utils/sqrt.rs @@ -10,7 +10,7 @@ use crate::prelude::*; /// pub fn sqrt(value: &BigInt) -> Result { if !value >= Zero::zero() { - return Err(Error::Incorrect("NEGATIVE".to_owned())); + return Err(Error::Incorrect("value has to be greater than -1".to_string())); } // If the value is less than or equal to MAX_SAFE_INTEGER, From 686d2239a8e85a3cd6726c215702b82022e3fa25 Mon Sep 17 00:00:00 2001 From: Malik672 Date: Thu, 11 Jan 2024 13:12:14 +0100 Subject: [PATCH 2/5] remove redendant code + 0.9.0 --- src/error.rs | 1 - src/utils/sorted_insert.rs | 14 +++++++++----- src/utils/sqrt.rs | 4 +++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/error.rs b/src/error.rs index 749df38..83f3894 100644 --- a/src/error.rs +++ b/src/error.rs @@ -2,7 +2,6 @@ use crate::prelude::*; #[derive(Debug, Error)] pub enum Error { - #[error("Chain IDs do not match: {0} and {1}")] ChainIdMismatch(u32, u32), diff --git a/src/utils/sorted_insert.rs b/src/utils/sorted_insert.rs index 4468946..30bd394 100644 --- a/src/utils/sorted_insert.rs +++ b/src/utils/sorted_insert.rs @@ -9,11 +9,15 @@ pub fn sorted_insert( comparator: fn(&T, &T) -> Ordering, ) -> Result, Error> { if max_size == 0 { - return Err(Error::Incorrect("max_size can't be equals to zero".to_owned())); + return Err(Error::Incorrect( + "max_size can't be equals to zero".to_owned(), + )); } if items.len() > max_size { - return Err(Error::Incorrect("items_size has to greater than max_size".to_string())); + return Err(Error::Incorrect( + "items_size has to greater than max_size".to_string(), + )); } let removed_item = if items.len() == max_size { @@ -47,18 +51,18 @@ mod tests { } #[test] - #[should_panic(expected = "MAX_SIZE_ZERO")] + #[should_panic(expected = "max_size can't be equals to zero")] fn test_max_size_zero() { let mut arr = Vec::new(); sorted_insert(&mut arr, 1, 0, cmp).unwrap(); } #[test] - #[should_panic(expected = "ITEMS_SIZE")] + #[should_panic(expected = "items_size has to greater than max_size")] fn test_length_greater_than_max_size() { let mut arr = vec![1, 2]; let _w = sorted_insert(&mut arr, 1, 1, cmp).unwrap(); - assert!(_w.is_none(), "ITEMS_SIZE"); + assert!(_w.is_none(), "items_size has to greater than max_size"); } #[test] diff --git a/src/utils/sqrt.rs b/src/utils/sqrt.rs index aa02e20..6e120f0 100644 --- a/src/utils/sqrt.rs +++ b/src/utils/sqrt.rs @@ -10,7 +10,9 @@ use crate::prelude::*; /// pub fn sqrt(value: &BigInt) -> Result { if !value >= Zero::zero() { - return Err(Error::Incorrect("value has to be greater than -1".to_string())); + return Err(Error::Incorrect( + "value has to be greater than -1".to_string(), + )); } // If the value is less than or equal to MAX_SAFE_INTEGER, From a06d50f8f5cf0b61df2055e80d44392e43eb3f8e Mon Sep 17 00:00:00 2001 From: Malik672 Date: Thu, 11 Jan 2024 13:30:53 +0100 Subject: [PATCH 3/5] remove redendant code + 0.9.0 --- src/utils/sorted_insert.rs | 6 +++--- src/utils/sqrt.rs | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/utils/sorted_insert.rs b/src/utils/sorted_insert.rs index 30bd394..44adb61 100644 --- a/src/utils/sorted_insert.rs +++ b/src/utils/sorted_insert.rs @@ -16,7 +16,7 @@ pub fn sorted_insert( if items.len() > max_size { return Err(Error::Incorrect( - "items_size has to greater than max_size".to_string(), + "items_size has to lesser than max_size".to_string(), )); } @@ -58,11 +58,11 @@ mod tests { } #[test] - #[should_panic(expected = "items_size has to greater than max_size")] + #[should_panic(expected = "items_size has to lesser than max_size")] fn test_length_greater_than_max_size() { let mut arr = vec![1, 2]; let _w = sorted_insert(&mut arr, 1, 1, cmp).unwrap(); - assert!(_w.is_none(), "items_size has to greater than max_size"); + assert!(_w.is_none(), "items_size has to lesser than max_size"); } #[test] diff --git a/src/utils/sqrt.rs b/src/utils/sqrt.rs index 6e120f0..069b66c 100644 --- a/src/utils/sqrt.rs +++ b/src/utils/sqrt.rs @@ -10,9 +10,7 @@ use crate::prelude::*; /// pub fn sqrt(value: &BigInt) -> Result { if !value >= Zero::zero() { - return Err(Error::Incorrect( - "value has to be greater than -1".to_string(), - )); + return Err(Error::Incorrect("value cannot be negative".to_string())); } // If the value is less than or equal to MAX_SAFE_INTEGER, From b1cee76728a7634a1864e97b931d034e37fb25e5 Mon Sep 17 00:00:00 2001 From: Malik672 Date: Thu, 11 Jan 2024 13:35:16 +0100 Subject: [PATCH 4/5] remove redendant code + 0.9.0 --- src/utils/sorted_insert.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utils/sorted_insert.rs b/src/utils/sorted_insert.rs index 44adb61..35e8bda 100644 --- a/src/utils/sorted_insert.rs +++ b/src/utils/sorted_insert.rs @@ -10,13 +10,13 @@ pub fn sorted_insert( ) -> Result, Error> { if max_size == 0 { return Err(Error::Incorrect( - "max_size can't be equals to zero".to_owned(), + "max_size can't be equal to zero".to_owned(), )); } if items.len() > max_size { return Err(Error::Incorrect( - "items_size has to lesser than max_size".to_string(), + "array length cannot exceed max_size".to_string(), )); } @@ -58,11 +58,11 @@ mod tests { } #[test] - #[should_panic(expected = "items_size has to lesser than max_size")] + #[should_panic(expected = "array length cannot exceed max_size")] fn test_length_greater_than_max_size() { let mut arr = vec![1, 2]; let _w = sorted_insert(&mut arr, 1, 1, cmp).unwrap(); - assert!(_w.is_none(), "items_size has to lesser than max_size"); + assert!(_w.is_none(), "array length cannot exceed max_size"); } #[test] From cda64672992c333fee8e354c79eb57ff07cecdcb Mon Sep 17 00:00:00 2001 From: Malik672 Date: Thu, 11 Jan 2024 13:39:52 +0100 Subject: [PATCH 5/5] remove redendant code + 0.9.0 --- src/utils/sorted_insert.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/sorted_insert.rs b/src/utils/sorted_insert.rs index 35e8bda..1688d5b 100644 --- a/src/utils/sorted_insert.rs +++ b/src/utils/sorted_insert.rs @@ -51,7 +51,7 @@ mod tests { } #[test] - #[should_panic(expected = "max_size can't be equals to zero")] + #[should_panic(expected = "max_size can't be equal to zero")] fn test_max_size_zero() { let mut arr = Vec::new(); sorted_insert(&mut arr, 1, 0, cmp).unwrap();