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
pub mod feed;
pub mod html;
pub mod http;
pub mod json;
pub mod print;
pub mod use_as;
use async_trait::async_trait;
use super::{result::TransformedEntry, Transform};
use crate::{
action::transform::error::{TransformError, TransformErrorKind},
entry::Entry,
};
use std::fmt::Debug;
#[async_trait]
pub trait TransformEntry: Debug {
type Err: Into<TransformErrorKind>;
async fn transform_entry(&self, entry: Entry) -> Result<Vec<TransformedEntry>, Self::Err>;
}
#[async_trait]
impl<T> Transform for T
where
T: TransformEntry + Send + Sync,
{
async fn transform(&self, old_entry: Entry) -> Result<Vec<Entry>, TransformError> {
self.transform_entry(old_entry.clone())
.await
.map(|vec| {
vec.into_iter()
.map(|transformed_entry| transformed_entry.into_entry(&old_entry))
.collect()
})
.map_err(|kind| TransformError {
kind: kind.into(),
original_entry: old_entry,
})
}
}