What is Rust, and when should you use it?
Rust is a modern programming language that is rapidly gaining popularity. It is low-level language with high-level features, which compiles directly to machine code (assembly).
The most distinctive new invention of Rust, is the concept of Ownership (ownership). It is a solution to a fundamental aspect of how computers work today: keeping track of what data can be released into your working memory. As an application runs, it typically loads more and more data into working memory. Every computation needs working memory. It is the responsibility of the software to free up this working memory again when it can. Traditionally, two solutions to this problem were:
Rust introduces a third solution to memory management: Ownership. In Rust, every variable (every piece of data in your working memory) is owned by a certain scope. When a variable leaves this scope, the piece of data can be pulled from working memory. An elegant solution, as this does not cost the application any extra time, allowing you to achieve the full 100% of the theoretically achievable speed.
WebAssembly is a standard to describe applications with. It is not so much a programming language, but a compilation target (just like the Assembly mentioned earlier). So it is (almost) not written by humans, but programming languages can compile to it. With almost all compiled applications, they must compile to a specific target (a specific architecture). For example, an application for Windows has a different binary than one for MacOS, or for Linux. This means that you as a developer have to take that into account, and thus offer (quite a lot of) different versions. That takes time, and makes the distribution of your application a lot more complicated.
What makes WebAssembly interesting is that it runs practically everywhere. The same WebAssembly code runs on x86, Arm, 32bit, 64bit.... It is designed to run in Browsers, as an alternative to Javascript. This allows some tasks to run a lot faster. It also allows you to reuse code from a programming language that compiles to WebAssembly, without having to rewrite it in Javascript.
But WebAssembly is not only interesting for browsers. WebAssembly runtimes are environments that can run WebAssembly, as is in your browser. We can also use these runtimes in a server context. The features that make it suitable for browsers also enable a whole new kind of server architecture. It starts up fast, it's secure, it's lightweight. For example, the emerging FaaS (Functions as a Service) architecture works very well with WebAssembly. For example, Amazon with Lambda and Cloudflare with their Workers already offer ways to write server logic with WebAssembly. In addition, WebAssembly is also an interesting language for developing plug-in architecture. All in all, there are lots of applications for WebAssembly that will now grow in popularity in the coming years.
One of the unique advantages to Rust, is how well it compiles to WebAssembly. The generated binaries are fast to execute, start up quickly and are also compact. The community that works on WebAssembly also largely works in Rust, and so you can see that there is a lot of good tooling for Rust + WebAssembly.
Rust can work in almost any context, but it is especially useful in server-side or embedded applications. If you want to create a web application, and the server writes in Rust, you'll still need front-end technology A few suitable options (that we also work with a lot) are: