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
use crate::{
function::{BoxedFunction, UserFunctions},
ruleset::{rule::Rule, RuleSet},
};
pub fn ruleset() -> Builder {
Builder {
rules: Vec::new(),
functions: UserFunctions::default(),
}
}
pub struct Builder {
rules: Vec<Rule>,
functions: UserFunctions,
}
impl Builder {
pub fn with_rule(mut self, rule: Rule) -> Self {
self.rules.push(rule);
self
}
pub fn with_rules(mut self, rules: impl IntoIterator<Item = Rule>) -> Self {
for rule in rules {
self.rules.push(rule)
}
self
}
pub fn with_function(mut self, function: BoxedFunction) -> Builder {
self.functions.add_function(function);
self
}
pub fn with_functions<I: IntoIterator<Item = BoxedFunction>>(mut self, functions: I) -> Self {
self.functions.add_functions(functions);
self
}
pub fn build(self) -> RuleSet {
RuleSet {
rules: self.rules,
functions: self.functions,
}
}
}