Is there any planning ERB-like functionality for Rust?

Hi all! I was curious if something similar to Ruby's ERB templating system exists or has planned support in Rust. Having some kind of .ers file for templating in HTML or other file types would be awesome! Thanks.

1 Like

You can find various crates providing similar functionality under the template engine category at crates.io: https://crates.io/categories/template-engine

1 Like

awesome! thanks so much, these look very promising

ERB allows Ruby to be embedded within the template. It seems like all of the rust libs have recreated their own embedded language instead of using rust as the embedded language. This means two languages needs to be learned by the dev when using these libs. I haven’t yet tried rust, but this is one of the first libraries I was seeking out to try. I’m curious if it would even be possible.

It's possible, just 100% pointless. Rust advantage is the compile-time error checking, disadvantage is lack of flexibility (you need to plan your programs and data types in advance). Ruby advantage is flexibility (dynamic types means you can just write code without thinking about types), disadvantage is late error checking.

When you combine Rust with template system you get something with negatives from both approaches (compile time error checking is impossible for obvious reasons) and zero positives (you still don't have flexibility of dynamic typing).

Just why would anyone want that thing?

I think you're making an assumption that the template can't be compiled.
Thinking on this more, it should definitely be possible. E.g. C#'s Razor pages embeds C# and gets compiled.

For Rust, the static parts of the templates could be converted to a series of format! commands or something appropriate, and the code parts just compiled as they are. This means the compiled templates would have compile-time checking and type safety, and all the other benefits of Rust... it would blow the other templating libraries out of the water.

Because everyone (or most people) would prefer to use the full power of their codebase's language.
Let's reverse that question... Why would anyone choose to use a different language in their templates if they could instead use Rust?

You might be looking for something like leptos? It's quite different in implementation, but allows interleaving markup and native Rust code

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.