askama
askama copied to clipboard
`num as {integer}` cast does not work?
Hi, I have this MRE:
use askama::Template;
#[derive(Template)]
#[template(ext = "txt", source = r#"
{% let a = 51 %} // works
{% let a = 51 as i64 %} // does not work
"#)]
struct HelloTemplate {}
fn main() {
let a = 51 as i64; // sanity check that it works in normal Rust code
let hello = HelloTemplate {};
println!("{}", hello.render().unwrap());
}
and it doesn't compile because of the line with casting as i64
.
Is there some alternative syntax for it that I'm missing?
It's possible we don't support as
casts. Maybe 51_i64
is supported? I forget...
Nope, doesn't work either :(
use askama::Template;
#[derive(Template)]
#[template(ext = "txt", source = r#"
{% let a = 51 %} // works
{% let a = 51_i64 %} // does not work
"#)]
struct HelloTemplate {}
fn main() {
let a = 51_i64; // sanity check that it works in normal Rust code
let hello = HelloTemplate {};
println!("{}", hello.render().unwrap());
}
Okay, well, if you want to try hacking it in, the code for binary expressions is around here:
https://github.com/djc/askama/blob/main/askama_parser/src/expr.rs#L107
If you can submit a patch with a basic test I'm happy to review it and/or provide more guidance.
In the meantime using i64::from(51)
should work.