Skip to content

Commit

Permalink
fix: fixed hasher value
Browse files Browse the repository at this point in the history
  • Loading branch information
m62624 committed Sep 9, 2023
1 parent f1b21cd commit 82d436a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
12 changes: 8 additions & 4 deletions flexible_inspect_rs/src/rules/rule_bytes/another_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,14 @@ mod hash_trait {
which means that they are identical anyway, so we only need to hash `all_rules`
*/
impl Hash for SimpleRulesBytes {
fn hash<H: std::hash::Hasher>(&self, _: &mut H) {
self.smr_must_be_found.hasher();
self.smr_must_not_be_found_with_subrules.hasher();
self.smr_must_not_be_found_without_subrules.hasher();
fn hash<H: Hasher>(&self, state: &mut H) {
// Create a hasher
let all_items = self
.smr_must_be_found
.iter()
.chain(&self.smr_must_not_be_found_with_subrules)
.chain(&self.smr_must_not_be_found_without_subrules);
all_items.for_each(|item| item.hash(state));
}
}
}
Expand Down
21 changes: 16 additions & 5 deletions flexible_inspect_rs/src/rules/rule_str/another_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,26 @@ mod hash_trait {
which means that they are identical anyway, so we only need to hash `all_rules`
*/
impl Hash for SimpleRules {
fn hash<H: std::hash::Hasher>(&self, _: &mut H) {
self.smr_must_be_found.hasher();
self.smr_must_not_be_found_with_subrules.hasher();
self.smr_must_not_be_found_without_subrules.hasher();
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
let all_items = self
.smr_must_be_found
.iter()
.chain(&self.smr_must_not_be_found_with_subrules)
.chain(&self.smr_must_not_be_found_without_subrules);
all_items.for_each(|item| item.hash(state));
}
}

impl Hash for Subrules {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {}
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.simple_rules.hash(state);
match &self.complex_rules {
Some(complex_rules_value) => {
complex_rules_value.iter().for_each(|rule| rule.hash(state));
}
None => 0.hash(state),
}
}
}
}

Expand Down

0 comments on commit 82d436a

Please sign in to comment.