Skip to main content

rswappalyzer_engine/core/
cached_rule.rs

1use rustc_hash::FxHashMap;
2use serde::{Deserialize, Serialize};
3
4use crate::{MatchCondition, MatchScope, Pattern, TechBasicInfo};
5
6
7
8// 作用域级别的缓存规则,包含条件+模式,无冗余
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct CachedScopeRule {
11    pub condition: MatchCondition,
12    // 列表型规则(Url/Html/Script/ScriptSrc)
13    pub list_patterns: Option<Vec<Pattern>>,
14    // KV型规则(Header/Meta),直接存储键值对,无需拼接字符串
15    pub keyed_patterns: Option<FxHashMap<String, Vec<Pattern>>>,
16}
17
18/// 规则库缓存结构(仅包含运行期所需的稳定数据)
19#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct CachedTechRule {
21    pub basic: TechBasicInfo, // 技术基础信息(含 tech_name)
22    // 按作用域聚合规则,1个作用域 = 1个条目,避免重复存储 condition
23    pub rules: FxHashMap<MatchScope, CachedScopeRule>,
24}
25
26/// 缓存用:单条规则项(稳定、可序列化)
27#[derive(Debug, Clone, Serialize, Deserialize)]
28pub struct CachedRuleEntry {
29    /// 匹配作用域(url / html / header / meta 等)
30    pub scope: MatchScope,
31    /// AND / OR
32    pub condition: MatchCondition,
33    /// 具体模式列表
34    pub patterns: Vec<Pattern>,
35}