Skip to main content

srs/
srs.rs

1use std::{fs, path::Path};
2
3use domi::{
4    AttrFilter, Entries,
5    srs::{Rule, RuleSet},
6};
7
8const BASE: &str = "alphabet";
9
10fn main() {
11    let data_root = Path::new("data");
12    let content = fs::read_to_string(data_root.join(BASE)).unwrap();
13    let mut entries = Entries::parse(BASE, content.lines());
14    while let Some(i) = entries.next_include() {
15        let include = fs::read_to_string(data_root.join(i.value.as_ref())).unwrap();
16        entries.parse_extend(i.value.as_ref(), BASE, include.lines());
17    }
18    // change the `Some(&[AttrFilter::Lacks("attr2")])` to something else can alter behavier,
19    // see crate::Entries
20    let rule = Rule::from(
21        entries
22            .flatten(BASE, Some(&[AttrFilter::Lacks("attr2")]))
23            .unwrap(),
24    );
25    // expected output {"version":1,"rules":[{"domain_suffix":["alphabet.com"],"domain_keyword":["fitbit","google"]}]}
26    let rule_set = RuleSet::from_iter([rule]);
27    println!("{}", serde_json::to_string(&rule_set).unwrap());
28}