Announcing: FAR

Posted 2020-01-28 17:35:45.936605498 UTC

Find And Replace: a dead-simple string template engine

Have you ever wanted a string templating engine in Rust that has basically no features? Well, your dreams have now come true! Let me introduce you to Find And Replace (FAR): a string template engine with basically no features. I'll start with a feature comparison with a more popular templating engine:

Finding and replacingYesYes
High performanceYesMaybe
Easy to debugYesMaybe
Template inheritanceYesNo
Control structuresYesNo
Sandboxed execution environmentYesNo
Automatic HTML escapingYesNo
Configurable syntaxYesNo
Optional ahead-of-time compilationYesNo
And many, many othersYesNo

As you can see, this is far simpler. (Sorry.) The reasoning for this is twofold. Firstly, implementing all the features of Jinja2 is a lot of work, I wrote FAR in roughly 8 hours. Secondly, It's my opinion that embedding logic in data is a recipe for maintenance chaos. I agree to disagree with you if you're of the opinion that control structures in external templates is a very useful feature. You're probably right, but I personally don't feel like I need it.

(As a side note, control structures in internal templates like maud are fine IMO, because the data is embedded into the code instead of the other way around. You'll pay the price in compilation times though, which is actually one of the main reasons I wrote FAR in the first place.)

"Weird, but alright," you're thinking, "but show me some code already! How would I even use this?"

Excellent question. Now, since I haven't gotten syntax highlighting working on this site yet, and the existing code blocks are hard to read on mobile, I'm just going to link you to the docs instead of copying the examples here. Odds are, you'll probably want to see the function signature (yes, there's only one) and such anyway. After checking out the docs, you may want to know more about how FAR decides to handle errors and other weird edge cases, and that information can be found here.

I'm also using this in "production" here (relevant source code), but it's currently a very simple use. I've got some ideas about changing the site's colorscheme based on URL parameters though, so watch out for that. Anyway.

Thanks for checking out FAR! If you've got any ideas, questions, or concerns, there's a Matrix room for discussion at, or of course the reddit thread.