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