From 5b029cff31c4bb9e793c536f295eaab6ba3a7a21 Mon Sep 17 00:00:00 2001 From: Mansur Azatbek Date: Mon, 28 Aug 2023 16:50:55 +0600 Subject: [PATCH] refactor: added `i8` type for `RangeBoundaries` --- flexible_inspect_rs/src/rules/common_elements/range.rs | 9 +++++++++ .../src/rules/common_elements/str_to_number.rs | 2 ++ 2 files changed, 11 insertions(+) diff --git a/flexible_inspect_rs/src/rules/common_elements/range.rs b/flexible_inspect_rs/src/rules/common_elements/range.rs index 3a1188d..589ede2 100644 --- a/flexible_inspect_rs/src/rules/common_elements/range.rs +++ b/flexible_inspect_rs/src/rules/common_elements/range.rs @@ -16,6 +16,7 @@ pub enum RangeFormat { #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Debug, Clone)] pub enum RangeBoundaries { + I8(RangeInclusive), I32(RangeInclusive), I64(RangeInclusive), I128(RangeInclusive), @@ -23,6 +24,12 @@ pub enum RangeBoundaries { F64(RangeInclusive), } +impl RangeType for RangeInclusive { + fn get_range(self) -> RangeBoundaries { + RangeBoundaries::I8(self) + } +} + impl RangeType for RangeInclusive { fn get_range(self) -> RangeBoundaries { RangeBoundaries::I32(self) @@ -65,6 +72,7 @@ pub enum RangeMode { impl Hash for RangeBoundaries { fn hash(&self, state: &mut H) { match self { + RangeBoundaries::I8(range) => range.hash(state), RangeBoundaries::I32(range) => range.hash(state), RangeBoundaries::I64(range) => range.hash(state), RangeBoundaries::I128(range) => range.hash(state), @@ -83,6 +91,7 @@ impl Hash for RangeBoundaries { impl PartialEq for RangeBoundaries { fn eq(&self, other: &Self) -> bool { match (self, other) { + (RangeBoundaries::I8(range1), RangeBoundaries::I8(range2)) => range1 == range2, (RangeBoundaries::I32(range1), RangeBoundaries::I32(range2)) => range1 == range2, (RangeBoundaries::I64(range1), RangeBoundaries::I64(range2)) => range1 == range2, (RangeBoundaries::I128(range1), RangeBoundaries::I128(range2)) => range1 == range2, diff --git a/flexible_inspect_rs/src/rules/common_elements/str_to_number.rs b/flexible_inspect_rs/src/rules/common_elements/str_to_number.rs index fb7582b..00c3065 100644 --- a/flexible_inspect_rs/src/rules/common_elements/str_to_number.rs +++ b/flexible_inspect_rs/src/rules/common_elements/str_to_number.rs @@ -36,3 +36,5 @@ where None } } + +