by throwawaymaths · 1y ago · 0 comments
I was reading an article about rust posted here yesterday and i realized: i have no clue what is going on in this code (also i presume "templage" is a typo):
#[derive(Debug, Default)]
pub struct Context {
authed: bool,
}
#[derive(Template)]
#[templage = "layout.jinja"]
struct HomeTemplate {
ctx: Context
};
pub async fn home() -> impl
IntoResponse {
HtmlTemplate(
HomeTemplate { ctx:
Context::default() }
).into_response()
}I love Rust and do some advanced code sometimes, but very rarely have I created a macro. I still see it more or less like "magic" that "super-human" library developers master to make their life easier. Typically not my use case.
This is another advantage of Zig. As you may know, metaprogramming in Zig doesn't use any special syntax, but rather the Zig language itself. This is often known as comptime and while not necessarily easy to grasp, as you're reasoning about compile time stuff, at least it's done in pure Zig.