Using Rust for web development
This is just my experience with Rust. Not a guide.
This whole website is built with Rust. Currently, it hosts 6.2GB of
data: sqlite3 databases, pre-genereated preview images for fancy social network previews, static
files, and
the source code of the website.
Want to see some metrics? Navigate to /metrics.
The experience
It's good.
I would assume that learning Rust by building a website and search engine
is somewhat suboptimal.
Especially when I didn't read the documentation to the language and
had to bruteforce my way through the compiler errors with my now beloved unwrap()
and then have to deal with panics.
Additionally, I used a lot of dependencies that ease the development process.
I use Rocket for HTTP server; Askama for the templating engine; sqlx to communicate with sqlite3
databases; Chrono for dates; Rand, Regex, Serde, Urlencoding for all other stuff.
Unpleasanties
Dependencies
An unpleasant surprise was the fact that I need to import a hefty amount of dependencies to get a
website running. When I just started with Rust, I assumed that I would have something from standard library for
math/crypto random. But no. At the same time I'm going from the Go background, where they have
quite rich
standard library.
Compilation time
It takes a while on AMD Ryzen 7 7840U. I have total of 231 dependencies (225 in final binary).
Clean build takes 38 seconds with dev profile and 1m 07s with release profile.
Incremental takes 1.17 seconds with dev, 4.07 seconds with release.
Closest comparison that I have is my vpub-plus forum engine
written in Go, which takes 0.61s to compile.
It's still faster than compiling NextJS-based projects though.
Pleasanties
Language itself. It's hard for me to pinpoint what I like the most about it.
Compiler. Errors are descriptive and I like the formatting that they designed for errors.
Cargo. I just like when programming language goes with its package manager.
Documentation. The Rust Programming Language, Rust Exercises, Rust by Example.