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)
}
}