Comment by slopinthebag
18 hours ago
one thing i love about rust's macros is that you can accomplish this without needing a separate file type or inventing syntax
#[component]
pub fn HomePage(user: Option<User>) -> Element {
rsx! {
Layout {
title: "Home",
if let Some(u) = user {
h1 { "Welcome back, {u.name}!" }
a { href: "/users/{u.id}", "Your profile" }
} else {
h1 { "Welcome, guest!" }
a { href: "/login", "Log in" }
}
}
}
}
> you can accomplish this
That's not HTML though, you have to learn a whole new dsl that must conform to rust parser rules. So, not the same thing at all.
You can do actual html. This is Leptos, a Solidjs like rust library:
does it still work if you remove that space before the tag's closing character in this line?
i prefer it, but you can also get html if you want
eg
but you have invented syntax
This is just Twig templates, crazy. It's cool that Rust can do this out of a box
yep and you get rust's lsp support too, autoformatting, etc.
this is rsx, but there are other macros that look just like html. i prefer this though, it's much more compact and readable imo
I'm not a fan of Rust, the overly flexible macros are actually one reason for it, but if you can indeed get LSP support in a custom syntax like this, that's really awesome. Thank you for the example.
1 reply →
[dead]
That is super cool actually