Skip to content

Commit

Permalink
Add each rule to the compiler instead of joining
Browse files Browse the repository at this point in the history
Since compiler.add_source allows for it to be called multiple times,
we can simply loop over each rule and call it once for each, rather than
trying to join all the rules into one big string then compiling.
  • Loading branch information
Robin5605 committed Jul 27, 2024
1 parent c15bf1e commit f4dd697
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/client/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,10 @@ pub struct RulesResponse {
impl RulesResponse {
/// Compile the rules from the response
pub fn compile(&self) -> Result<yara_x::Rules> {
let rules_str = self
.rules
.values()
.map(String::as_ref)
.collect::<Vec<&str>>()
.join("\n");

let mut compiler = yara_x::Compiler::new();
compiler.add_source(rules_str.as_str())?;
for source in self.rules.values() {
compiler.add_source(source.as_str())?;
}

Ok(compiler.build())
}
Expand Down

0 comments on commit f4dd697

Please sign in to comment.