Skip to content
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

Ability to add filters, functions, and tests with dynamic names #145

Closed
SergioBenitez opened this issue Nov 14, 2022 · 1 comment · Fixed by #146
Closed

Ability to add filters, functions, and tests with dynamic names #145

SergioBenitez opened this issue Nov 14, 2022 · 1 comment · Fixed by #146

Comments

@SergioBenitez
Copy link
Contributor

At present, the Environment::{add_filter, add_function, add_test} methods make it impossible to add filter/function/tests with dynamic (String) names as they expect an &'source str. In my application, filters, functions, and tests are loaded dynamically, so I cannot possibly generate an &str for the names unless I go through some unsafety and keep self-references around. Alternatively, I can simply leak the String, but this is far from ideal.

Ideally, I could simply pass the String to the appropriate method and have that be it. It's not evident to me what's being saved here as a result of using an &str solely, so my proposal is to allow N: Into<Cow<'source, str>> instead, and store the name as a Cow<'source, str>.

SergioBenitez added a commit to SergioBenitez/minijinja that referenced this issue Nov 14, 2022
@mitsuhiko
Copy link
Owner

I think this is very sensible. This also is an issue that needs addressing for #135 too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants