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
62
63
64
65
66
67
68
69
70
71
72
73
74
pub mod caps;
pub mod set;
pub mod shorten;
pub mod trim;
use self::{caps::Caps, set::Set, shorten::Shorten, trim::Trim};
use super::result::TransformResult;
use crate::{
action::regex::{action::Extract, action::Replace, Regex},
error::transform::Kind as TransformErrorKind,
};
use derive_more::From;
pub trait TransformField {
type Error: Into<TransformErrorKind>;
#[allow(clippy::missing_errors_doc)]
fn transform_field(&self, field: Option<&str>) -> Result<TransformResult<String>, Self::Error>;
}
#[allow(missing_docs)]
#[derive(From, Debug)]
pub enum Kind {
RegexExtract(Regex<Extract>),
RegexReplace(Regex<Replace>),
Set(Set),
Caps(Caps),
Trim(Trim),
Shorten(Shorten),
}
#[derive(Debug)]
pub enum Field {
Title,
Body,
Link,
}
impl TransformField for Kind {
type Error = TransformErrorKind;
fn transform_field(
&self,
field: Option<&str>,
) -> Result<TransformResult<String>, TransformErrorKind> {
macro_rules! delegate {
($($k:tt),+) => {
match self {
$(Self::$k(x) => x.transform_field(field).map_err(Into::into),)+
}
};
}
delegate!(RegexExtract, RegexReplace, Set, Caps, Trim, Shorten)
}
}