My adventures in Rust webdev

The framework

The most popular Rust web frameworks today are Iron and Nickel, but there exist several other personal web frameworks with a few github stars each. As far as I can tell, all the frameworks that I found in my quick overview are express-like middlewares-based frameworks.

Templates

Since the old website was using HTML templates written in mustache, I decided to keep that system and use the mustache Rust library.

Caching

First of all, I had the idea to use a caching mechanism for the templates. The first time I use a template, it would compile it and store it in memory. Then when you reuse the same template, it would load the already-compiled template from the cache. The cache itself was stored in a lazy_static!.

Usability

Just like the middlewares system that I talked about earlier, the mustache templating system was designed for weakly-typed languages. For example when you write {{#foo}}, the value of foo passed from Rust can be an Option, a struct, a Vec, a boolean, a function, and so on.

Postgres

I’m using the postgres library in order to connect to the database. It works great, if you except… OpenSSL.

OpenSSL

Everyone who has tried web development in Rust for some time probably knows what I mean. This library is a nightmare. It is for example the reason why I’m using a Linux virtual machine to develop on my Windows machine, instead of compiling for Windows directly.

Postgres‘s usability

The postgres library itself can be a little tedious to use. I started the project by writing code that would manually read columns from result sets. This makes the code really tedious to write and difficult to read.

Chrono

One thing I didn’t mention is that the code manipulates a lot of dates and hours. It is in fact from this area that most of the bugs in the old code came from, as handling date/times in Javascript is a total clusterfuck.

Deployment

Every popular language has its utilities and tutorials about how to properly deploy a web service written in that language. But Rust doesn’t.

Overall

Overall I’m quite satisfied of Rust. I still wouldn’t recommend web development in Rust for everyone, unless it’s really worth it or if you like to figure out things yourself. But it’s (very) slowly getting there.

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store