From 791da719535245ab6d31d718c76988f2243e3b2f Mon Sep 17 00:00:00 2001 From: Mansur Azatbek Date: Tue, 29 Aug 2023 23:13:56 +0600 Subject: [PATCH] refactor: improved code, removed warnings --- .../src/rules/common_elements/mod.rs | 16 +++++------ flexible_inspect_rs/src/rules/init.rs | 4 +-- .../src/rules/next/counter_status.rs | 4 +-- flexible_inspect_rs/src/rules/next/mod.rs | 4 +-- .../src/rules/next/modifier_arena.rs | 2 +- .../src/rules/next/number_range_status.rs | 2 +- .../src/rules/rule_bytes/convert/mod.rs | 28 +++++++++---------- .../src/rules/rule_bytes/runner_range.rs | 28 +++++++++---------- .../src/rules/rule_str/runner_range.rs | 16 +++++------ .../all_rules_for_all_matches.rs | 6 ++-- .../all_rules_for_at_least_one_match.rs | 4 +-- .../at_least_one_rule_for_all_matches.rs | 4 +-- ...t_least_one_rule_for_at_least_one_match.rs | 6 ++-- .../src/rules/runner/context_match/mod.rs | 1 - flexible_inspect_rs/src/rules/runner/mod.rs | 8 +++--- flexible_inspect_rs/src/rules/traits.rs | 10 +++---- 16 files changed, 71 insertions(+), 72 deletions(-) diff --git a/flexible_inspect_rs/src/rules/common_elements/mod.rs b/flexible_inspect_rs/src/rules/common_elements/mod.rs index ceab35b..46febca 100644 --- a/flexible_inspect_rs/src/rules/common_elements/mod.rs +++ b/flexible_inspect_rs/src/rules/common_elements/mod.rs @@ -1,7 +1,7 @@ use std::marker::PhantomData; use self::range::RangeFormat; -use super::{traits::IntoConcreteType, *}; +use super::{traits::IntoSpecificCaptureType, *}; pub mod range; // ======================================================= /// This is reserved standard value for error filling @@ -81,29 +81,29 @@ pub enum Counter { /// A structure that stores all the data for processing the capture #[derive(Debug)] -pub struct CaptureData<'a, T: IntoConcreteType<'a>> { +pub struct CaptureData<'a, T: IntoSpecificCaptureType<'a>> { pub text_for_capture: IndexSet, pub hashmap_for_error: HashMap, pub counter_value: usize, pub phantom: PhantomData<&'a T>, } -impl<'a> IntoConcreteType<'a> for &'a str { - fn into_str(&self) -> Option<&'a str> { +impl<'a> IntoSpecificCaptureType<'a> for &'a str { + fn as_str(&self) -> Option<&'a str> { Some(self) } - fn into_bytes(&self) -> Option<&'a [u8]> { + fn as_bytes(&self) -> Option<&'a [u8]> { None } } -impl<'a> IntoConcreteType<'a> for &'a [u8] { - fn into_str(&self) -> Option<&'a str> { +impl<'a> IntoSpecificCaptureType<'a> for &'a [u8] { + fn as_str(&self) -> Option<&'a str> { None } - fn into_bytes(&self) -> Option<&'a [u8]> { + fn as_bytes(&self) -> Option<&'a [u8]> { Some(self) } } diff --git a/flexible_inspect_rs/src/rules/init.rs b/flexible_inspect_rs/src/rules/init.rs index 0e083eb..f38622f 100644 --- a/flexible_inspect_rs/src/rules/init.rs +++ b/flexible_inspect_rs/src/rules/init.rs @@ -1,4 +1,4 @@ -use super::{rule_str::RegexRaw, traits::IntoConcreteType, *}; +use super::{rule_str::RegexRaw, traits::IntoSpecificCaptureType, *}; use crate::prelude::Rule; impl GeneralModifiers { @@ -39,7 +39,7 @@ impl SlisedRules { } } -impl<'a, T: IntoConcreteType<'a>> CaptureData<'a, T> { +impl<'a, T: IntoSpecificCaptureType<'a>> CaptureData<'a, T> { pub fn is_some(&self) -> bool { !self.text_for_capture.is_empty() } diff --git a/flexible_inspect_rs/src/rules/next/counter_status.rs b/flexible_inspect_rs/src/rules/next/counter_status.rs index 17ed139..e42733a 100644 --- a/flexible_inspect_rs/src/rules/next/counter_status.rs +++ b/flexible_inspect_rs/src/rules/next/counter_status.rs @@ -2,13 +2,13 @@ use log::error; use super::*; use crate::rules::{ - traits::{IntoConcreteType, RuleBase}, + traits::{IntoSpecificCaptureType, RuleBase}, Counter, }; /// The counter implementation impl Counter { - pub fn counter_status<'a, R: RuleBase, C: IntoConcreteType<'a>>( + pub fn counter_status<'a, R: RuleBase, C: IntoSpecificCaptureType<'a>>( rule: &R, captures: &mut CaptureData<'a, C>, ) -> NextStep { diff --git a/flexible_inspect_rs/src/rules/next/mod.rs b/flexible_inspect_rs/src/rules/next/mod.rs index f6fdaec..ef2f7c5 100644 --- a/flexible_inspect_rs/src/rules/next/mod.rs +++ b/flexible_inspect_rs/src/rules/next/mod.rs @@ -2,7 +2,7 @@ mod counter_status; mod modifier_arena; pub mod number_range_status; use super::{ - traits::{IntoConcreteType, RuleBase}, + traits::{IntoSpecificCaptureType, RuleBase}, *, }; @@ -19,7 +19,7 @@ pub enum NextStep { impl NextStep { /// Mechanism with final variant, depending on modifiers we get the result - pub fn next_or_finish_or_error<'a, R: RuleBase, C: IntoConcreteType<'a>>( + pub fn next_or_finish_or_error<'a, R: RuleBase, C: IntoSpecificCaptureType<'a>>( rule: &R, captures: &mut CaptureData<'a, C>, ) -> NextStep { diff --git a/flexible_inspect_rs/src/rules/next/modifier_arena.rs b/flexible_inspect_rs/src/rules/next/modifier_arena.rs index 43af893..2f5375e 100644 --- a/flexible_inspect_rs/src/rules/next/modifier_arena.rs +++ b/flexible_inspect_rs/src/rules/next/modifier_arena.rs @@ -5,7 +5,7 @@ use super::*; /// Additional checks of modifiers are performed here /// ( if there will be more of them and they will take a long time to calculate, /// we will switch to checking via `async_task` for each modifier ) -pub fn modifier_runner<'a, R: RuleBase, C: IntoConcreteType<'a>>( +pub fn modifier_runner<'a, R: RuleBase, C: IntoSpecificCaptureType<'a>>( rule: &R, captures: &mut CaptureData<'a, C>, ) -> NextStep { diff --git a/flexible_inspect_rs/src/rules/next/number_range_status.rs b/flexible_inspect_rs/src/rules/next/number_range_status.rs index 62a81b5..2063509 100644 --- a/flexible_inspect_rs/src/rules/next/number_range_status.rs +++ b/flexible_inspect_rs/src/rules/next/number_range_status.rs @@ -2,7 +2,7 @@ use super::*; use crate::rules::rule_bytes::runner_range::single_bytes_result; use crate::rules::rule_str::runner_range::single_str_result; -pub fn number_range_status<'a, R: RuleBase, C: IntoConcreteType<'a>>( +pub fn number_range_status<'a, R: RuleBase, C: IntoSpecificCaptureType<'a>>( rule: &R, captures: &mut CaptureData<'a, C>, ) -> NextStep { diff --git a/flexible_inspect_rs/src/rules/rule_bytes/convert/mod.rs b/flexible_inspect_rs/src/rules/rule_bytes/convert/mod.rs index e77bd58..cf8f08c 100644 --- a/flexible_inspect_rs/src/rules/rule_bytes/convert/mod.rs +++ b/flexible_inspect_rs/src/rules/rule_bytes/convert/mod.rs @@ -62,7 +62,7 @@ impl FromBytes for i8 { fn from_be_bytes_non_const(bytes: &[u8]) -> Option { if bytes.len() == I8_LEN { let mut array_bytes: [u8; I8_LEN] = Default::default(); - array_bytes.copy_from_slice(&bytes); + array_bytes.copy_from_slice(bytes); return Some(i8::from_be_bytes(array_bytes)); } else { warn!( @@ -81,7 +81,7 @@ impl FromBytes for i8 { fn from_le_bytes_non_const(bytes: &[u8]) -> Option { if bytes.len() == I8_LEN { let mut array_bytes: [u8; I8_LEN] = Default::default(); - array_bytes.copy_from_slice(&bytes); + array_bytes.copy_from_slice(bytes); return Some(i8::from_le_bytes(array_bytes)); } else { warn!( @@ -102,7 +102,7 @@ impl FromBytes for i16 { fn from_be_bytes_non_const(bytes: &[u8]) -> Option { if bytes.len() == I16_LEN { let mut array_bytes: [u8; I16_LEN] = Default::default(); - array_bytes.copy_from_slice(&bytes); + array_bytes.copy_from_slice(bytes); return Some(i16::from_be_bytes(array_bytes)); } else { warn!( @@ -121,7 +121,7 @@ impl FromBytes for i16 { fn from_le_bytes_non_const(bytes: &[u8]) -> Option { if bytes.len() == I16_LEN { let mut array_bytes: [u8; I16_LEN] = Default::default(); - array_bytes.copy_from_slice(&bytes); + array_bytes.copy_from_slice(bytes); return Some(i16::from_le_bytes(array_bytes)); } else { warn!( @@ -142,7 +142,7 @@ impl FromBytes for i32 { fn from_be_bytes_non_const(bytes: &[u8]) -> Option { if bytes.len() == I32_LEN { let mut array_bytes: [u8; I32_LEN] = Default::default(); - array_bytes.copy_from_slice(&bytes); + array_bytes.copy_from_slice(bytes); return Some(i32::from_be_bytes(array_bytes)); } else { warn!( @@ -161,7 +161,7 @@ impl FromBytes for i32 { fn from_le_bytes_non_const(bytes: &[u8]) -> Option { if bytes.len() == I32_LEN { let mut array_bytes: [u8; I32_LEN] = Default::default(); - array_bytes.copy_from_slice(&bytes); + array_bytes.copy_from_slice(bytes); return Some(i32::from_le_bytes(array_bytes)); } else { warn!( @@ -182,7 +182,7 @@ impl FromBytes for i64 { fn from_be_bytes_non_const(bytes: &[u8]) -> Option { if bytes.len() == I64_LEN { let mut array_bytes: [u8; I64_LEN] = Default::default(); - array_bytes.copy_from_slice(&bytes); + array_bytes.copy_from_slice(bytes); return Some(i64::from_be_bytes(array_bytes)); } else { warn!( @@ -201,7 +201,7 @@ impl FromBytes for i64 { fn from_le_bytes_non_const(bytes: &[u8]) -> Option { if bytes.len() == I64_LEN { let mut array_bytes: [u8; I64_LEN] = Default::default(); - array_bytes.copy_from_slice(&bytes); + array_bytes.copy_from_slice(bytes); return Some(i64::from_le_bytes(array_bytes)); } else { warn!( @@ -222,7 +222,7 @@ impl FromBytes for i128 { fn from_be_bytes_non_const(bytes: &[u8]) -> Option { if bytes.len() == I128_LEN { let mut array_bytes: [u8; I128_LEN] = Default::default(); - array_bytes.copy_from_slice(&bytes); + array_bytes.copy_from_slice(bytes); return Some(i128::from_be_bytes(array_bytes)); } else { warn!( @@ -241,7 +241,7 @@ impl FromBytes for i128 { fn from_le_bytes_non_const(bytes: &[u8]) -> Option { if bytes.len() == I128_LEN { let mut array_bytes: [u8; I128_LEN] = Default::default(); - array_bytes.copy_from_slice(&bytes); + array_bytes.copy_from_slice(bytes); return Some(i128::from_le_bytes(array_bytes)); } else { warn!( @@ -262,7 +262,7 @@ impl FromBytes for f32 { fn from_be_bytes_non_const(bytes: &[u8]) -> Option { if bytes.len() == F32_LEN { let mut array_bytes: [u8; F32_LEN] = Default::default(); - array_bytes.copy_from_slice(&bytes); + array_bytes.copy_from_slice(bytes); return Some(f32::from_be_bytes(array_bytes)); } else { warn!( @@ -281,7 +281,7 @@ impl FromBytes for f32 { fn from_le_bytes_non_const(bytes: &[u8]) -> Option { if bytes.len() == F32_LEN { let mut array_bytes: [u8; F32_LEN] = Default::default(); - array_bytes.copy_from_slice(&bytes); + array_bytes.copy_from_slice(bytes); return Some(f32::from_le_bytes(array_bytes)); } else { warn!( @@ -302,7 +302,7 @@ impl FromBytes for f64 { fn from_be_bytes_non_const(bytes: &[u8]) -> Option { if bytes.len() == F64_LEN { let mut array_bytes: [u8; F64_LEN] = Default::default(); - array_bytes.copy_from_slice(&bytes); + array_bytes.copy_from_slice(bytes); return Some(f64::from_be_bytes(array_bytes)); } else { warn!( @@ -321,7 +321,7 @@ impl FromBytes for f64 { fn from_le_bytes_non_const(bytes: &[u8]) -> Option { if bytes.len() == F64_LEN { let mut array_bytes: [u8; F64_LEN] = Default::default(); - array_bytes.copy_from_slice(&bytes); + array_bytes.copy_from_slice(bytes); return Some(f64::from_le_bytes(array_bytes)); } else { warn!( diff --git a/flexible_inspect_rs/src/rules/rule_bytes/runner_range.rs b/flexible_inspect_rs/src/rules/rule_bytes/runner_range.rs index 6d39e67..af1fe0f 100644 --- a/flexible_inspect_rs/src/rules/rule_bytes/runner_range.rs +++ b/flexible_inspect_rs/src/rules/rule_bytes/runner_range.rs @@ -4,14 +4,14 @@ use std::{ str::FromStr, }; -use super::rules::{next::NextStep, traits::IntoConcreteType}; +use super::rules::{next::NextStep, traits::IntoSpecificCaptureType}; use super::{convert::FromBytes, *}; fn single_range_bytes_check< 'a, T: FromStr + Copy + Debug + Display + PartialOrd + FromBytes, - C: IntoConcreteType<'a>, + C: IntoSpecificCaptureType<'a>, >( numbers: &mut CaptureData<'a, C>, range: &RangeInclusive, @@ -26,12 +26,12 @@ fn single_range_bytes_check< .filter(|&num| { let num = match read_mode { ReadMode::FromBeBytes => { - T::from_be_bytes_non_const(num.into_bytes().unwrap()) + T::from_be_bytes_non_const(num.as_bytes().unwrap()) } ReadMode::FromLeBytes => { - T::from_le_bytes_non_const(num.into_bytes().unwrap()) + T::from_le_bytes_non_const(num.as_bytes().unwrap()) } - ReadMode::FromUtf8 => T::from_utf8(num.into_bytes().unwrap()), + ReadMode::FromUtf8 => T::from_utf8(num.as_bytes().unwrap()), }; num.map(|num| range.contains(&num)).unwrap_or(false) }) @@ -45,12 +45,12 @@ fn single_range_bytes_check< .filter(|&num| { let num = match read_mode { ReadMode::FromBeBytes => { - T::from_be_bytes_non_const(num.into_bytes().unwrap()) + T::from_be_bytes_non_const(num.as_bytes().unwrap()) } ReadMode::FromLeBytes => { - T::from_le_bytes_non_const(num.into_bytes().unwrap()) + T::from_le_bytes_non_const(num.as_bytes().unwrap()) } - ReadMode::FromUtf8 => T::from_utf8(num.into_bytes().unwrap()), + ReadMode::FromUtf8 => T::from_utf8(num.as_bytes().unwrap()), }; num.map(|num| range.contains(&num)).unwrap_or(false) }) @@ -65,12 +65,12 @@ fn single_range_bytes_check< .filter(|&num| { let num = match read_mode { ReadMode::FromBeBytes => { - T::from_be_bytes_non_const(num.into_bytes().unwrap()) + T::from_be_bytes_non_const(num.as_bytes().unwrap()) } ReadMode::FromLeBytes => { - T::from_le_bytes_non_const(num.into_bytes().unwrap()) + T::from_le_bytes_non_const(num.as_bytes().unwrap()) } - ReadMode::FromUtf8 => T::from_utf8(num.into_bytes().unwrap()), + ReadMode::FromUtf8 => T::from_utf8(num.as_bytes().unwrap()), }; num.map(|num| range.contains(&num)).unwrap_or(false) }) @@ -84,7 +84,7 @@ fn single_range_bytes_check< pub fn single_bytes_result< 'a, T: Debug + FromStr + Copy + Display + PartialOrd + FromBytes, - C: IntoConcreteType<'a>, + C: IntoSpecificCaptureType<'a>, >( range_bytes: &RangeBytes, captures: &mut CaptureData<'a, C>, @@ -96,8 +96,8 @@ pub fn single_bytes_result< range_bytes.range_mode, &range_bytes.read_mode, ) { - return NextStep::Finish; + NextStep::Finish } else { - return NextStep::Error(Some(std::mem::take(&mut captures.hashmap_for_error))); + NextStep::Error(Some(std::mem::take(&mut captures.hashmap_for_error))) } } diff --git a/flexible_inspect_rs/src/rules/rule_str/runner_range.rs b/flexible_inspect_rs/src/rules/rule_str/runner_range.rs index 46069f9..c4e5008 100644 --- a/flexible_inspect_rs/src/rules/rule_str/runner_range.rs +++ b/flexible_inspect_rs/src/rules/rule_str/runner_range.rs @@ -1,4 +1,4 @@ -use super::rules::{next::NextStep, traits::IntoConcreteType}; +use super::rules::{next::NextStep, traits::IntoSpecificCaptureType}; use super::{convert::convert_and_filter, *}; use std::{ fmt::{Debug, Display}, @@ -9,7 +9,7 @@ use std::{ fn single_range_str_check< 'a, T: FromStr + Copy + Debug + Display + PartialOrd, - C: IntoConcreteType<'a>, + C: IntoSpecificCaptureType<'a>, >( captures: &mut CaptureData<'a, C>, range: &RangeInclusive, @@ -21,7 +21,7 @@ fn single_range_str_check< .text_for_capture .iter() .filter(|&num| { - convert_and_filter(num.into_str().unwrap()) + convert_and_filter(num.as_str().unwrap()) .map(|num| range.contains(&num)) .unwrap_or(false) }) @@ -33,7 +33,7 @@ fn single_range_str_check< .text_for_capture .iter() .filter(|&num| { - convert_and_filter(num.into_str().unwrap()) + convert_and_filter(num.as_str().unwrap()) .map(|num| range.contains(&num)) .unwrap_or(false) }) @@ -46,7 +46,7 @@ fn single_range_str_check< .text_for_capture .iter() .filter(|&num| { - convert_and_filter(num.into_str().unwrap()) + convert_and_filter(num.as_str().unwrap()) .map(|num| range.contains(&num)) .unwrap_or(false) }) @@ -60,15 +60,15 @@ fn single_range_str_check< pub fn single_str_result< 'a, T: Debug + FromStr + Copy + Display + PartialOrd, - C: IntoConcreteType<'a>, + C: IntoSpecificCaptureType<'a>, >( range_str: &RangeStr, captures: &mut CaptureData<'a, C>, value: &RangeInclusive, ) -> NextStep { if single_range_str_check(captures, value, range_str.range_mode) { - return NextStep::Finish; + NextStep::Finish } else { - return NextStep::Error(Some(std::mem::take(&mut captures.hashmap_for_error))); + NextStep::Error(Some(std::mem::take(&mut captures.hashmap_for_error))) } } diff --git a/flexible_inspect_rs/src/rules/runner/context_match/all_rules_for_all_matches.rs b/flexible_inspect_rs/src/rules/runner/context_match/all_rules_for_all_matches.rs index b497dca..a03d1b3 100644 --- a/flexible_inspect_rs/src/rules/runner/context_match/all_rules_for_all_matches.rs +++ b/flexible_inspect_rs/src/rules/runner/context_match/all_rules_for_all_matches.rs @@ -6,8 +6,8 @@ pub fn all_rules_for_all_matches<'a, R, C>( stack: &mut VecDeque<(&'a R::RuleType, CaptureData<'a, C>)>, ) -> NextStep where - R: CalculateValueRules<'a, C> + Debug, - C: IntoConcreteType<'a>, + R: CalculateValueRules<'a, C>, + C: IntoSpecificCaptureType<'a>, { let mut temp_stack: VecDeque<(&R::RuleType, CaptureData)> = VecDeque::new(); if let Some(mut frame) = stack.pop_front() { @@ -199,7 +199,7 @@ fn not_in_regexset<'a, R, C>( ) -> NextStep where R: CalculateValueRules<'a, C> + Debug, - C: IntoConcreteType<'a>, + C: IntoSpecificCaptureType<'a>, { // ============================= LOG ============================= debug!( diff --git a/flexible_inspect_rs/src/rules/runner/context_match/all_rules_for_at_least_one_match.rs b/flexible_inspect_rs/src/rules/runner/context_match/all_rules_for_at_least_one_match.rs index 366e233..cda6def 100644 --- a/flexible_inspect_rs/src/rules/runner/context_match/all_rules_for_at_least_one_match.rs +++ b/flexible_inspect_rs/src/rules/runner/context_match/all_rules_for_at_least_one_match.rs @@ -6,8 +6,8 @@ pub fn all_rules_for_at_least_one_match<'a, R, C>( stack: &mut VecDeque<(&'a R::RuleType, CaptureData<'a, C>)>, ) -> NextStep where - R: CalculateValueRules<'a, C> + Debug, - C: IntoConcreteType<'a>, + R: CalculateValueRules<'a, C>, + C: IntoSpecificCaptureType<'a>, { let mut temp_stack: VecDeque<(&R::RuleType, CaptureData)> = VecDeque::new(); diff --git a/flexible_inspect_rs/src/rules/runner/context_match/at_least_one_rule_for_all_matches.rs b/flexible_inspect_rs/src/rules/runner/context_match/at_least_one_rule_for_all_matches.rs index fd800cb..9c168ad 100644 --- a/flexible_inspect_rs/src/rules/runner/context_match/at_least_one_rule_for_all_matches.rs +++ b/flexible_inspect_rs/src/rules/runner/context_match/at_least_one_rule_for_all_matches.rs @@ -6,8 +6,8 @@ pub fn at_least_one_rule_for_all_matches<'a, R, C>( stack: &mut VecDeque<(&'a R::RuleType, CaptureData<'a, C>)>, ) -> NextStep where - R: CalculateValueRules<'a, C> + Debug, - C: IntoConcreteType<'a> + R: CalculateValueRules<'a, C>, + C: IntoSpecificCaptureType<'a>, { let mut temp_stack = Some(VecDeque::new()); if let Some(mut frame) = stack.pop_front() { diff --git a/flexible_inspect_rs/src/rules/runner/context_match/at_least_one_rule_for_at_least_one_match.rs b/flexible_inspect_rs/src/rules/runner/context_match/at_least_one_rule_for_at_least_one_match.rs index 738c0c6..c80bc81 100644 --- a/flexible_inspect_rs/src/rules/runner/context_match/at_least_one_rule_for_at_least_one_match.rs +++ b/flexible_inspect_rs/src/rules/runner/context_match/at_least_one_rule_for_at_least_one_match.rs @@ -3,11 +3,11 @@ use super::*; /// in this mode, at least one rule must be passed for at least on match pub fn at_least_one_rule_for_at_least_one_match<'a, R, C>( // get a unique stack of one root, necessary to bypass the recursion constraint - stack: &mut VecDeque<(&'a R::RuleType, CaptureData<'a,C>)>, + stack: &mut VecDeque<(&'a R::RuleType, CaptureData<'a, C>)>, ) -> NextStep where - R: CalculateValueRules<'a, C> + Debug, - C: IntoConcreteType<'a>, + R: CalculateValueRules<'a, C>, + C: IntoSpecificCaptureType<'a>, { let mut temp_stack: Option)>> = Some(VecDeque::new()); if let Some(mut frame) = stack.pop_front() { diff --git a/flexible_inspect_rs/src/rules/runner/context_match/mod.rs b/flexible_inspect_rs/src/rules/runner/context_match/mod.rs index 536d6f6..1a6fa35 100644 --- a/flexible_inspect_rs/src/rules/runner/context_match/mod.rs +++ b/flexible_inspect_rs/src/rules/runner/context_match/mod.rs @@ -14,4 +14,3 @@ pub use at_least_one_rule_for_at_least_one_match::at_least_one_rule_for_at_least use log::{debug, error, info, trace}; use std::collections::{HashMap, HashSet, VecDeque}; use std::fmt::Debug; -use std::hash::Hash; diff --git a/flexible_inspect_rs/src/rules/runner/mod.rs b/flexible_inspect_rs/src/rules/runner/mod.rs index 20b0b1f..e18d146 100644 --- a/flexible_inspect_rs/src/rules/runner/mod.rs +++ b/flexible_inspect_rs/src/rules/runner/mod.rs @@ -1,11 +1,11 @@ mod context_match; -use super::traits::IntoConcreteType; +use super::traits::IntoSpecificCaptureType; use super::*; use crate::rules::next::NextStep; use crate::rules::traits::{CalculateValueRules, RuleBase}; use colored::*; use log::debug; -use std::{collections::VecDeque, fmt::Debug}; +use std::collections::VecDeque; /// Main method for iteratively running a rule /// Goes through all subrules, and so on to the end for each `Rule`. @@ -31,8 +31,8 @@ Step 3 */ pub fn run<'a, R, C>(rule: &'a R::RuleType, data: CaptureData<'a, C>) -> NextStep where - R: CalculateValueRules<'a, C> + Debug, - C: IntoConcreteType<'a>, + R: CalculateValueRules<'a, C>, + C: IntoSpecificCaptureType<'a>, { // ============================= LOG ============================= debug!( diff --git a/flexible_inspect_rs/src/rules/traits.rs b/flexible_inspect_rs/src/rules/traits.rs index 140d698..a0c213f 100644 --- a/flexible_inspect_rs/src/rules/traits.rs +++ b/flexible_inspect_rs/src/rules/traits.rs @@ -15,7 +15,7 @@ use std::{fmt::Debug, hash::Hash}; pub trait RuleBase { type TakeRuleType; type SubRulesType; - type RuleType: Debug; + type RuleType; type RegexSet; fn _new>(pattern: T, requirement: MatchRequirement) -> Self; @@ -37,7 +37,7 @@ pub trait RuleBase { /// The main thing is to implement separately `Captures` for `&str` and `&[u8]` /// the rest will be the same -pub trait CalculateValueRules<'a, C: IntoConcreteType<'a>> { +pub trait CalculateValueRules<'a, C: IntoSpecificCaptureType<'a>>: Debug { type RuleType: RuleBase + Hash + Eq @@ -80,7 +80,7 @@ pub trait RangeType { fn get_range(self) -> RangeBoundaries; } -pub trait IntoConcreteType<'a>: Hash + PartialEq + Eq + Debug { - fn into_str(&self) -> Option<&'a str>; - fn into_bytes(&self) -> Option<&'a [u8]>; +pub trait IntoSpecificCaptureType<'a>: Hash + PartialEq + Eq + Debug { + fn as_str(&self) -> Option<&'a str>; + fn as_bytes(&self) -> Option<&'a [u8]>; }