tera icon indicating copy to clipboard operation
tera copied to clipboard

Allow runtime creation of `Function`s and `Filter`s by relaxing type parameters

Open k12ish opened this issue 3 years ago • 1 comments

Currently, functions and filters have to be 'static:

pub fn register_function<F: Function + 'static>(
    &mut self,
    name: &str,
    function: F
)

This prevents you from generating an arbitrary number of functions at runtime.

Functions and Filters don't need to be 'static, they only need to live as long as the Tera instance they are attached to.

Currently, you can workaround this using unsafe { std::mem::transmute(...) } to get a 'static lifetime.

I'm not too fussed if you don't want this implemented, let me know what you think!

k12ish avatar Oct 27 '22 12:10 k12ish

I can't remember why its using 'static tbh I wouldn't change it in the current version but we can add it to the https://github.com/Keats/tera/issues/637 list

Keats avatar Oct 27 '22 19:10 Keats