Skip to content

Commit

Permalink
refactor: changed Range type
Browse files Browse the repository at this point in the history
  • Loading branch information
m62624 committed Aug 28, 2023
1 parent 3ad508b commit 519e909
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 4 deletions.
1 change: 0 additions & 1 deletion flexible_inspect_rs/src/rules/common_elements/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use self::range::RangeFormat;

use super::*;
pub mod range;
pub mod str_to_number;
Expand Down
10 changes: 10 additions & 0 deletions flexible_inspect_rs/src/rules/rule_bytes/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,13 @@ impl SimpleRulesBytes {
}
}
}

impl RangeBytes {
pub fn new(range: range::RangeBoundaries, read_mode: ReadMode, range_mode: RangeMode) -> Self {
Self {
range,
read_mode,
range_mode,
}
}
}
3 changes: 2 additions & 1 deletion flexible_inspect_rs/src/rules/rule_bytes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ pub struct RegexSetContainer {
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct RangeBytes {
pub range: RangeBoundaries,
pub read_mod: ReadMode,
pub read_mode: ReadMode,
pub range_mode: RangeMode,
}

/// Byte reading modes
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
Expand Down
19 changes: 18 additions & 1 deletion flexible_inspect_rs/src/rules/rule_bytes/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::range::RangeFormat;
use super::rules::traits::{CalculateValueRules, RangeType};
use super::*;
use crate::rules::traits::CalculateValueRules;

impl CalculateValueRules<'_, &[u8]> for RuleBytes {
type RegexSet = regex::bytes::RegexSet;
Expand All @@ -12,3 +13,19 @@ impl CalculateValueRules<'_, &[u8]> for RuleBytes {
captures::find_captures(rule, capture)
}
}

impl RuleBytes {
pub fn number_range<RNG: RangeType>(
mut self,
range: RNG,
read_bytes_mode: ReadMode,
range_mode: RangeMode,
) -> RuleBytes {
self.0.general_modifiers.range = Some(RangeFormat::Bytes(RangeBytes::new(
range.get_range(),
read_bytes_mode,
range_mode,
)));
self
}
}
6 changes: 6 additions & 0 deletions flexible_inspect_rs/src/rules/rule_str/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,9 @@ impl SimpleRules {
}
}
}

impl RangeStr {
pub fn new(range: range::RangeBoundaries, range_mode: RangeMode) -> Self {
Self { range, range_mode }
}
}
14 changes: 13 additions & 1 deletion flexible_inspect_rs/src/rules/rule_str/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use super::range::RangeFormat;
use super::rule_str::Rule;
use super::*;
use crate::rules::traits::CalculateValueRules;
use crate::rules::traits::{CalculateValueRules, RangeType};

impl CalculateValueRules<'_, &str> for Rule {
type RegexSet = regex::RegexSet;
Expand All @@ -12,3 +14,13 @@ impl CalculateValueRules<'_, &str> for Rule {
captures::find_captures(rule, capture)
}
}

impl Rule {
pub fn number_range<RNG: RangeType>(mut self, range: RNG, range_mode: RangeMode) -> Rule {
self.0.general_modifiers.range = Some(RangeFormat::Str(RangeStr::new(
range.get_range(),
range_mode,
)));
self
}
}

0 comments on commit 519e909

Please sign in to comment.