Building functional webapp with Rust: first experience 🔗

Rust is hand down a very complicated language. The price to pay for “Zero Cost Abstraction” is that we get mental model that are pretty clunky and hard to wrap our head around. Still, it is pretty satisfying to write a backend in Rust, for the following reason:

  • Performance: we are confident that our code run faster and more efficiently comparing to JS or Python
  • Concurrency control: Rust use a similar mental model of async/await comparing to JS by means of the tokio framework
  • Less hidden control flow: this is a sentiment shared by modern low-level languages like Rust such as Zig or Go. Error handling is made explicit using Result wrapper type. This means less unhandled exception to worry about.

Macro is also a very powerful metaprogramming tool. The crate sqlx employ a macro to transform raw SQL query into typesafe code at compile time by connecting to a dev database instance.

The overall premise of Rust is that, once you have finished wrestling with the typechecker, you have a fairly good chance of having a piece of code that do what you intended without any unexpected behavior.