solidhunter_lib/rules/
rule_impl.rs

1use crate::errors::SolidHunterError;
2use crate::rules::create_default_rules;
3use crate::rules::types::*;
4
5pub fn create_rules_file(path: &str) {
6    let rules = Rules {
7        name: "solidhunter".to_string(),
8        rules: create_default_rules(),
9    };
10    let serialized = serde_json::to_string_pretty(&rules).unwrap();
11
12    std::fs::write(path, serialized).unwrap();
13}
14
15pub fn parse_rules(path: &str) -> Result<Rules, SolidHunterError> {
16    if !std::path::Path::new(&path).is_file() {
17        return Err(SolidHunterError::IoError(std::io::Error::new(
18            std::io::ErrorKind::NotFound,
19            "Failed to load a solidhunter's config file",
20        )));
21    }
22    let file = std::fs::read_to_string(path)?;
23    let parsed: Rules = serde_json::from_str(&file)?;
24
25    Ok(parsed)
26}