summaryrefslogtreecommitdiff
path: root/src/parameterexpression.rs
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-09-28 21:34:12 +0200
committertroido <troido@protonmail.com>2020-09-28 21:34:12 +0200
commit5af83beb6f10023cef7eba192a0b190518fe967b (patch)
tree5d559de847d3492999496651ec52136dd31f58a4 /src/parameterexpression.rs
parentb7187e210ae7e794c87ae2f76d0f212e5d716b15 (diff)
better type validation and spawners set home argument on their spawned template
Diffstat (limited to 'src/parameterexpression.rs')
-rw-r--r--src/parameterexpression.rs8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/parameterexpression.rs b/src/parameterexpression.rs
index dfba562..0208fb9 100644
--- a/src/parameterexpression.rs
+++ b/src/parameterexpression.rs
@@ -32,11 +32,11 @@ pub enum EvaluationError {
impl ParameterExpression {
- pub fn evaluate(&self, arguments: &HashMap<String, Parameter>, template: &Template) -> Result<Parameter, EvaluationError> {
+ pub fn evaluate(&self, arguments: &HashMap<String, Option<Parameter>>, template: &Template) -> Result<Parameter, EvaluationError> {
self.evaluate_(arguments, template, 0)
}
- fn evaluate_(&self, arguments: &HashMap<String, Parameter>, template: &Template, nesting: usize) -> Result<Parameter, EvaluationError> {
+ fn evaluate_(&self, arguments: &HashMap<String, Option<Parameter>>, template: &Template, nesting: usize) -> Result<Parameter, EvaluationError> {
if nesting > MAX_NESTING {
return Err(EvaluationError::Other("Maximum nesting reached in parameter evaluation".to_string()));
}
@@ -61,7 +61,9 @@ impl ParameterExpression {
}))
}
Self::Argument(argname) => {
- Ok(arguments.get(argname.as_str()).ok_or(EvaluationError::MissingArgument(argname.to_string()))?.clone())
+ arguments.get(argname.as_str())
+ .ok_or(EvaluationError::Other(format!("unknown argument {}", argname)))?.clone()
+ .ok_or(EvaluationError::MissingArgument(argname.to_string()))
}
Self::Random(options) => {
let r = rand::thread_rng().gen_range(0, options.len());