1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
pub mod filter;
pub mod transform;
use self::{
filter::Filter,
transform::{error::TransformError, Transform},
};
use crate::entry::Entry;
#[derive(Debug)]
pub enum Action {
Filter(Box<dyn Filter>),
Transform(Box<dyn Transform>),
}
impl Action {
pub async fn process(&self, mut entries: Vec<Entry>) -> Result<Vec<Entry>, TransformError> {
match self {
Action::Filter(f) => {
f.filter(&mut entries).await;
Ok(entries)
}
Action::Transform(tr) => {
let mut fully_transformed = Vec::new();
for entry in entries {
fully_transformed.extend(tr.transform(entry).await?);
}
Ok(fully_transformed)
}
}
}
}
impl From<Box<dyn Filter>> for Action {
fn from(filter: Box<dyn Filter>) -> Self {
Action::Filter(filter)
}
}
impl From<Box<dyn Transform>> for Action {
fn from(transform: Box<dyn Transform>) -> Self {
Action::Transform(transform)
}
}