-
-
Notifications
You must be signed in to change notification settings - Fork 219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support closures in templates #284
Comments
Full closure support would mean arbitrary Rust code in templates, which is at odds with my design direction. What could work is figuring out how filters might interact with Can you give a bit more context on your use cases? |
The main use case is accessing a field of a struct inside an |
I'm having a hard time thinking of alternative syntaxes that could cover this use case well. What might work is having highly restricted support for closures, for example by only allow single expression bodies. I'm a bit worried about creating an uncanny valley effect where it's hard to know up front what is supported and what's not, but to some extent that probably can't be prevented. |
Maybe something filter-like along the lines of |
Okay, I'm open to having single-expression closures. However, I probably won't be able to implement them anytime soon. If anyone else is interested, I'm happy to provided guidance and/or mentoring! |
I would be interested in helping implement this |
Cool! Okay, so probably just start with the parser, implement a new expression variant Let me know if you have questions! |
Sweet, sounds pretty approachable. I'll take a stab at it. |
I think this is the issue I am having. I want to do
But this fails to compile. Is there a simple workaround? Or should I just implement this logic myself without using the closure? |
The simplest workaround would be to make a method on your context type that takes care of this logic, I think. |
Currently working with
Option
s can be rather frustrating and clumsy because of the lack of support for closures inside templates. Adding support for closures would significantly improve the library's usability.The text was updated successfully, but these errors were encountered: