1use crate::detector::PiiClass;
2pub use gaze_types::Action;
3
4#[derive(Debug, Clone, Default)]
5pub struct RuleContext {
6 pub field_name: Option<String>,
7}
8
9pub trait Rule: Send + Sync {
10 fn action(&self, class: &PiiClass, context: &RuleContext) -> Option<Action>;
11}
12
13pub struct ClassRule {
14 class: PiiClass,
15 action: Action,
16}
17
18impl ClassRule {
19 pub fn new(class: PiiClass, action: Action) -> Self {
20 Self { class, action }
21 }
22}
23
24impl Rule for ClassRule {
25 fn action(&self, class: &PiiClass, _context: &RuleContext) -> Option<Action> {
26 (self.class == *class).then_some(self.action)
27 }
28}
29
30pub struct ColumnRule {
31 field_name: String,
32 action: Action,
33}
34
35impl ColumnRule {
36 pub fn new(field_name: &str, action: Action) -> Self {
37 Self {
38 field_name: field_name.to_string(),
39 action,
40 }
41 }
42}
43
44impl Rule for ColumnRule {
45 fn action(&self, _class: &PiiClass, context: &RuleContext) -> Option<Action> {
46 (context.field_name.as_deref() == Some(self.field_name.as_str())).then_some(self.action)
47 }
48}
49
50pub struct DefaultRule {
51 action: Action,
52}
53
54impl DefaultRule {
55 pub fn new(action: Action) -> Self {
56 Self { action }
57 }
58}
59
60impl Rule for DefaultRule {
61 fn action(&self, _class: &PiiClass, _context: &RuleContext) -> Option<Action> {
62 Some(self.action)
63 }
64}