News for hackers. Stuff that matters.
Re:Hyper – A fast and correct HTTP implementation for Rust by infogulch on Friday May 12, 2023 @05:33PM (#35922708)
Any recommendations for rust template engines? I'd like something that can easily render labeled fragments of a template instead of requiring me to split a page into a dozen little files. Kinda like inline {{block}} definitions in Go's html/template. Speed is also nice.

From template-benchmark-rs [0] I found sailfish [1] (fast, but no fragments(?)). render-rs [2] and syn-rsx [3] both let you write html in rust macros which is cool (maybe that can substitute for fragments?). Then there's gtmpl-rust [4] which is just Go templates reimplemented in rust.

[0]: https://github.com/rosetta-rs/template-benchmarks-rs

[1]: https://github.com/rust-sailfish/sailfish

[2]: https://github.com/render-rs/render.rs last updated Jul 2020

[3]: https://github.com/stoically/syn-rsx last updated Nov 2022

[4]: https://github.com/fiji-flo/gtmpl-rust

Re:Hyper – A fast and correct HTTP implementation for Rust by tomjakubowski on Friday May 12, 2023 @05:38PM (#35922789)
tera is fairly standard. Jinja2-like syntax. I'm not sure what you mean about rendering labeled fragments, do you have an example?
Re:Hyper – A fast and correct HTTP implementation for Rust by infogulch on Friday May 12, 2023 @06:20PM (#35923223)
Sure. They're called 'partials' sometimes. Useful if you want to rerender just part of a page. This is a pattern used by HTMX, a 'js framework' that accepts fragments of html in an http response and injects it into the page. This is good because it avoids the flash and state loss of a whole page reload. See the HTMX essay on template fragments for a more complete argument [0].

This is a go template for an interactive todos app [1] that I'm experimenting with. The html content of the entire page is present in one template definition which is split into 6 inline {{block}} definitions / "fragments". The page supports 5 interactions indicated by {{define}} definitions, each of which reuse various block fragments relevant to that interaction. I'm in the process of converting it to use embedded cozodb [2] queries which act as a server side data store. The idea here is that the entire 'app', including all html fragments, styles, http requests and responses, db schema, and queries are embedded into this single 100-line file.

[0]: https://htmx.org/essays/template-fragments/

[1]: https://github.com/infogulch/go-htmx/blob/master/templates/t...

[2]: https://github.com/cozodb/cozo

Re:Hyper – A fast and correct HTTP implementation for Rust by langfan on Friday May 12, 2023 @07:05PM (#35923633)
>Sure. They're called 'partials' sometimes.

Same as partials in Rails, maybe. A while since I used it.

Re:Hyper – A fast and correct HTTP implementation for Rust by prussian on Friday May 12, 2023 @05:46PM (#35922889)