2 hours ago · Tech · hide

I've refactored this blog and some other web apps in Rust that I maintain from Jinja templates to a type-safe Rust macro. To illustrate the difference, let's start with a concrete Jinja template example: <style> .comment { border-left: thin var(--secondary-bg) solid; padding-left: 10px; } </style> <div class="comment"> <p> <strong>{{ name }}</strong> {% if site %} (<a href="https://{{ site }}" target="_blank">{{ site }}</a>) {% endif %} </p> {{ html_content | safe }} </div> This Jinja template uses variable replacement with {{ ... }}, control flow with {% if ... %}...{% endif %} and some kind of functional transformation (called "filters") with ... | .... It works and the Rust crate minijinja is pretty good. However, as it's common in template languages, the type system is weak and doesn't help catch common mistakes at all! To know which variables are used you have to carefully read the code. Since the IDE cannot understand the usage of struct fields, actions like "show usages" do not…

Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town