Show HN: Askama – Type-safe, compiled Jinja-like templates for Rust
github.com
github.com
Askama and Bart seem to be pretty similar in use (compile time, based on a struct definition) except for the template languages. Askama is rich, while Bart, like Mustache, is deliberately more restricted. ("Logicless", they would call it. I don't know how to quantify that.)
Kudos for porting Jinja to Rust.
Django is far more restrictive in what you can put between the braces. I think one of the design goals of it was that designers with little programming knowledge could write the templates, which is a noble idea but leads to frustration as anyone who has maintained a large django app will tell you.
They are also dog slow :(
Being Swift a compiled language just like Rust, why can we modify the templates (Stencil, Mustache) in Swift without recompiling the app but not in Rust?
I don't see compiling them as a big downside, either. What problems do you see with that?
Tera (https://github.com/Keats/tera) exists already if that's more your cup of tea.
On the other hand, perhaps it could parse them dynamically in debug mode (and statically in release mode), but notice that the library creates a structure to hold the data that is inserted into the template. In debug mode it would have to do dynamic lookups into that structure, which means capturing its layout for use at run time. All the other template features would likewise need some run-time implementation. You'd end up writing everything twice. If you're willing to do that extra work, you might instead think about writing a JIT compiler for your template language. Instead of caching the AST of a template, a JIT implementation would generate and cache runnable code.
On the gripping hand, one of the things that makes static compilation possible here is that the template compiler uses macros to generate Rust code, which the Rust compiler then compiles. To do a JIT you would either have to write your own compiler, or embed all of Rust (and LLVM) into the application. You wouldn't be the first to make a language that makes the entire compiler available at run time, but there's always a cost to that.