-
I want to cache the compiled use std::cell::OnceCell;
use std::sync::OnceLock;
use minijinja::{Environment, Expression};
static ENVIRONMENT: OnceLock<Environment> = OnceLock::new();
pub struct Variable {
_condition: String,
condition: OnceCell<Expression<'static, 'static>>,
}
impl Variable {
fn compile(&self) {
let environment = ENVIRONMENT.get_or_init(|| Environment::empty());
let expression = environment
.compile_expression(&self._condition)
.expect("cannot compile expression");
let _ = self.condition.set(expression);
}
} But it failed to compile with the following error.
How can I deal with the lifetimes of |
Beta Was this translation helpful? Give feedback.
Answered by
mitsuhiko
Nov 19, 2023
Replies: 1 comment
-
Today that's not possible, but in the next version of minijinja it will be possible with |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
mitsuhiko
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Today that's not possible, but in the next version of minijinja it will be possible with
Environment::compile_expression_owned
. See #383