18

I'm running a server-side-rendered web server using Actix Web. Any suggestions for a client? All I really need is something fast and that I can use without breaking my neck (don't need any fancy VDOM, trying to ship minimal JS).

top 15 comments
sorted by: hot top controversial new old
[-] daluca@feddit.nz 5 points 1 year ago* (last edited 1 year ago)

Try askama, it also has a crate to integrate actix-web called askama_actix. It's jinja like template engine

[-] heartlessevil@lemmy.one 3 points 1 year ago

Can't beat askama. There are other Jinja-like templates but askama has best-in-class performance and compile time safety.

[-] oleid@programming.dev 2 points 1 year ago

When you say "best in class performance", do you have particular benchmarks in mind?

I only found this one: https://github.com/rosetta-rs/template-benchmarks-rs

Askama was neither fastest not slowest. Purely based on benchmarks sailfish seems to be interesting as well

[-] dukk@programming.dev 1 points 1 year ago* (last edited 1 year ago)

Is there any way to track values without a struct? Or in my specific case, I’m using a struct, but most of the values are in an Option<String>.

[-] livingcoder@lemmy.austinwadeheller.com 2 points 1 year ago* (last edited 1 year ago)

I've been using tide-jsx, but I'm also using tide (not actix). Everything renders to a String, so it would technically be compatible with any web framework.

I would love to see what other people suggest for Actix since I wanted to use that instead of Tide, but I also didn't know where to find a crate like tide-jsx. https://crates.io/crates/tide-jsx

[-] dukk@programming.dev 2 points 1 year ago

Thanks, this is a lot like what I was looking for. Will try it out.

[-] livingcoder@lemmy.austinwadeheller.com 1 points 1 year ago* (last edited 1 year ago)

You may need to fork the repo and mirror my pull requests into your fork. The maintainer of the repo hasn't responded to my pull requests yet and one of them fixes a common bug.

In your Cargo.toml file, you can reference your own fork as a dependency. https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#specifying-dependencies-from-git-repositories

[-] oleid@programming.dev 2 points 1 year ago

Check out these benchmarks. https://github.com/rosetta-rs/template-benchmarks-rs

Particularly the implementation of the benchmark for each crate.

[-] LPThinker@lemmy.world 1 points 1 year ago

My go to for static content is astro.js. It gives a really nice developer experience that is really just writing HTML but with the quality of life of reusable "components", all with 0 JS by default.

[-] dukk@programming.dev 2 points 1 year ago

Ultimately, I ended up using Astro, Rust was giving me too much pain for no tangible gain.

[-] darcy@sh.itjust.works 1 points 1 year ago

i have used the handlebars crate, and it is great for really simple templating. it is extensible with 'helpers', but imo a bit annoying for more complex use.

[-] ShittyKopper@lemmy.w.on-t.work 1 points 1 year ago

I came here to ask a similar question so I may as well throw it into the comments of this one just to make sure I don't end up cluttering the community.

In my case though, I have a few extra requirements the existing answers can't handle:

  1. It needs to be re-compiled/interpreted at runtime
  2. It should be able to handle reasonably untrustworthy input (not as in completely untrustworthy, but if someone makes a typo it shouldn't end up escalating into a security issue)
[-] dukk@programming.dev 1 points 1 year ago

I think all of these can be recompiled at runtime.

Askama seems to be a popular and mature option here. Yew is also pretty popular here, uses a VDOM and provides a powerful front end (great for SPAs) I’m most likely going to go with tide-jsx, it’s like HTML but it supports Rust expressions thru a macro, which is exactly what I need. Liquid is also pretty secure, so that’s an option.

Askama and Yew are pretty mature, so they probably have reasonable security. I would check their docs, however.

[-] ShittyKopper@lemmy.w.on-t.work 2 points 1 year ago

Perhaps "recompilation" wasn't the right word to use there.

My goal is to let people customize the templates that will end up building the pages, either from the app itself or through a companion panel app of sorts. This excludes anything that compiles down to native code, so it must be something interpreted at runtime.

[-] dukk@programming.dev 1 points 1 year ago

Maybe just store the template in a file, read it, and format with the strfmt library?

load more comments
view more: next ›
this post was submitted on 01 Jul 2023
18 points (100.0% liked)

Rust

5980 readers
101 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 1 year ago
MODERATORS