-
Notifications
You must be signed in to change notification settings - Fork 12
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
Minimize use of argument references for functions in templates #67
Comments
You can accept Would be nice to mention it in the book. |
Good suggestion to make the templates clearer. I do feel that In my case, they'd be wondering why an enum variant takes a |
In any case, proc-macros are very limited amount of information. We cannot assume the type most of the time. Calling Anyway, providing this information in the book in the |
I agree that proc-macros doesn't provide enough information. Could we get Or maybe I think users will be okay without Rinja magically doing the right thing as long as it's clear and obvious. Especially if it doesn't require them to change existing code to work with templates. |
I don't think using filters in arguments is a good idea. And I'd prefer to avoid doing too much magic with operators too. The current behaviour is coherent across all operations: we add a reference and filters should all expect a reference. |
I think the behavior of filters is fine. It's arguments to functions, including functions on template impl's, that are the trouble mainly because of these things I have experienced:
I'm not sure there's a great solution but what happens now feels awkward and clunky. For #1 I've worked around it by adding a For #2 it might be worth removing the special case handling of literals to avoid confusion. For the most part Rinja has been really nice to use and I see function arguments as the only real pain point I've encountered. |
Overall, whether we decide to remove reference in some cases or not, what's most important is coherency. If n some cases, there are no references and some others there are, it makes using rinja more tricky. I really think the best way forward here is to use references all the time and to recommend to our users to use
Glad you like it. :) |
Improving consistency in this area is probably be the easiest solution with with the most positive impact. I did have to look at the code to understand why sometimes I needed to accept a reference and sometimes not, removing the need for that would be helpful. I have found that adding helper methods on the |
Functions called in templates shouldn't require references for argument types that are
Copy
.For example:
{{{ my_function(my_integer) }}}
will requiremy_function
to accept a&u32
ifmy_integer
is a template field. Passing a u32 by reference is odd. Also, callingmy_function(42)
later in the same template would fail unless it was writtenmy_function(&42)
.This might not have an easy solution. This could be getting into compile-time type detection.
A work-around is to call a function on the argument to prevent Rinja from automatically adding the reference.
{{ my_function(my_integer.clone()) }}
works and allows the function to take au32
instead of&u32
.An example can be found in
testing/tests/calls.rs
.The text was updated successfully, but these errors were encountered: