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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
use std::borrow::Cow;
use std::fmt;
use abc::*;
use types::context::Context;
pub type EvalResult<T> = Result<Option<T>, EvalError>;
#[derive(Debug)]
pub enum EvalError {
NotInvocable,
NoneArg,
NotComposable,
AttributeNotExists(String),
Input(String),
Process(String),
}
pub type FilterResult<T> = Result<Option<T>, FilterError>;
#[derive(Debug)]
pub enum FilterError {
UnknownFormatter(String),
Input(String),
Process(String),
Format(fmt::Error),
}
impl From<fmt::Error> for FilterError { fn from(err: fmt::Error) -> Self { FilterError::Format(err) } }
pub trait Filter: fmt::Debug + Send + Sync {
fn filter<'s: 'a, 'a>(&'s self, context: &'a Context, value: Option<Cow<'a, BType>>) -> FilterResult<Cow<'a, BType>>;
}
pub type ParseResult<T> = Result<T, ParseError>;
#[derive(Debug)]
pub enum ParseError {
Syntax(String),
}
pub type RenderResult<T> = Result<T, RenderError>;
#[derive(Debug)]
pub enum RenderError {
LoadTemplate(LoadError),
ParseTemplate(ParseError),
VariableNotExists(String),
EvalExpression(EvalError),
Filter(FilterError),
FunctionCallException(String),
Format(fmt::Error),
}
impl From<LoadError> for RenderError { fn from(err: LoadError) -> Self { RenderError::LoadTemplate(err) } }
impl From<EvalError> for RenderError { fn from(err: EvalError) -> Self { RenderError::EvalExpression(err) } }
impl From<ParseError> for RenderError { fn from(err: ParseError) -> Self { RenderError::ParseTemplate(err) } }
impl From<FilterError> for RenderError { fn from(err: FilterError) -> Self { RenderError::Filter(err) } }
impl From<fmt::Error> for RenderError { fn from(err: fmt::Error) -> Self { RenderError::Format(err) } }