summaryrefslogtreecommitdiff
path: root/src/eval/value.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-03-03 17:53:40 +0100
committerLaurenz <laurmaedje@gmail.com>2021-03-03 17:53:40 +0100
commitc94a18833f23d2b57de1b87971458fd54b56d088 (patch)
tree9e1ed55cfca15aef6d39ced50a3a5b14d2800aae /src/eval/value.rs
parent4d90a066f197264341eff6bf67e8c06cae434eb4 (diff)
Closures and function definitions 🚀
Supports: - Closure syntax: `(x, y) => z` - Shorthand for a single argument: `x => y` - Function syntax: `let f(x) = y` - Capturing of variables from the environment - Error messages for too few / many passed arguments Does not support: - Named arguments - Variadic arguments with `..`
Diffstat (limited to 'src/eval/value.rs')
-rw-r--r--src/eval/value.rs10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/eval/value.rs b/src/eval/value.rs
index d910155a..7f31ea13 100644
--- a/src/eval/value.rs
+++ b/src/eval/value.rs
@@ -172,22 +172,22 @@ impl Debug for TemplateFunc {
/// A wrapper around a reference-counted executable function.
#[derive(Clone)]
pub struct ValueFunc {
- name: String,
+ name: Option<String>,
f: Rc<dyn Fn(&mut EvalContext, &mut ValueArgs) -> Value>,
}
impl ValueFunc {
/// Create a new function value from a rust function or closure.
- pub fn new<F>(name: impl Into<String>, f: F) -> Self
+ pub fn new<F>(name: Option<String>, f: F) -> Self
where
F: Fn(&mut EvalContext, &mut ValueArgs) -> Value + 'static,
{
- Self { name: name.into(), f: Rc::new(f) }
+ Self { name, f: Rc::new(f) }
}
/// The name of the function.
- pub fn name(&self) -> &str {
- &self.name
+ pub fn name(&self) -> Option<&str> {
+ self.name.as_deref()
}
}