dm_database_sqllog2db/pipeline/
processor.rs1use dm_database_parser_sqllog::Sqllog;
2
3pub trait LogProcessor: Send + Sync + std::fmt::Debug {
6 fn process(&self, record: &Sqllog) -> bool;
7
8 fn process_with_meta(&self, record: &Sqllog) -> bool {
11 self.process(record)
12 }
13}
14
15#[derive(Debug, Default)]
17pub struct Pipeline {
18 processors: Vec<Box<dyn LogProcessor>>,
19}
20
21impl Pipeline {
22 #[must_use]
23 pub fn new() -> Self {
24 Self::default()
25 }
26
27 pub fn add(&mut self, processor: Box<dyn LogProcessor>) {
28 self.processors.push(processor);
29 }
30
31 #[must_use]
32 pub fn is_empty(&self) -> bool {
33 self.processors.is_empty()
34 }
35
36 #[inline]
37 #[must_use]
38 pub fn run_with_meta(&self, record: &Sqllog) -> bool {
39 self.processors.iter().all(|p| p.process_with_meta(record))
40 }
41}