Support function calls - #304
Conversation
djc
left a comment
There was a problem hiding this comment.
This looks solid, thanks for fixing all those bugs! Some minor nits below.
|
You can just silence the clippy warnings by attaching |
|
There were no good reason for me not to use _visit_args indeed! However, I could not figure out why method calls needed to be scoped in _visit_args (e.g. &{ self.a.call() } instead of &self.a.call()), but I suppose if this had to be done for method calls, I should add it for function calls as well? |
I think so too! I don't remember off the top of my head, but I think some kinds of expressions will introduce temporary variables, and the scopes are used to make sure those are cleaned up again. Thanks for your contribution! |
This allows function calls in templates. There are multiple ways a function could be called: static callables (e.g. static functions), methods on template (in an impl block) and function pointer calls (template has an attribute of type e.g. FnOnce(args) -> String).
I tried to be consistent with the ways things are right now: i.e. {{ var }} refers to an attribute of the template, and path::CONST refers to a constant declared in the path module.
Case 1 :
callableis an attribute ofTemplate.Case 2:
callableis in the outer context (e.g. static function)Case 3:
callableis a method:Actually, methods are just static functions that take
&selfas an argument.This last case might seem weird at first, but it actually keeps things consistent in the mind of the programmer, i.e. {{ var }} refers to an attribute of the template and {{ path::var }} refers to something else.
I also need to update the documentation to explain this simply.
Fixes #285, fixes #196
EDIT: Removed reference to an issue that this does not actueally address.