You probably know that Rust has been voted “The Most Loved” programming language according to Stack Overflow developer surveys for seven years. Rust is starting to dominate every area of software. The software industry is interested in it because it needs a language like that. Now it’s also creeping into the cloud-native world thanks to the benefits brought by WebAssembly and WASI, technologies that are particularly Rust-friendly. The reasons Rust is liked and needed are multiple. I will tell you some of the main things that improve development experience, enhance the safety and increase the speed of your programs. I will also tell you how Rust can make you more productive.

Why Rust?

Let’s start by exploring why the software industry needs a language like Rust. This may help us realize why it’s so loved, too.

It helps us, fallible humans

When we are new programmers, we make a lot of mistakes (remember the times when a for loop was mystical?). Over time, we gain experience. We get to know our tools, algorithms, and data structures. We also get used to working with complicated software architectures. The problem with that is that it enables us to make more complex mistakes. These mistakes cost millions to companies investing time and money into finding and fixing complicated, subtle memory errors occurring in complex environments that, with Rust, are entirely avoided. So, we need more help from our tools to write code more safely and achieve reliable software from the ground up. We need a trainer, like Yoda, Rust trains developers.

Personally, I used to get many runtime errors when I used to write C or C++. I may be a bad programmer, but with Rust, once I understood its principles, I got fewer errors, and that made me enjoy programming more and even helped me feel more competent.

It makes you more productive

To answer the question of why Rust is so nice, we should first consider the following:

Why did we create programming languages and compilers in the first place?

In the 50s, we wrote programs with assembler, which was extremely difficult to write and read, while making mistakes was extremely easy. Over time, tools have evolved. For example, in the 70s, we got C, which is still widely used. It is much better than assembler; it’s much easier to write and read, and you get some help from the compiler to find mistakes in your code.

We needed more developer productivity.

So the reason we created programming languages and compilers is fourfold:

  • Easy language – We need something concise, easy to write and read, and more like English or mathematics.
  • Make a program portable – We need to run our program on different platforms.
  • Optimize – We wanted faster programs that take advantage of our hardware.
  • Finding Errors – We wanted to find mistakes we made while writing our code.

It’s in these last two items where Rust really shines, especially in the “Finding Errors” area. Rust produces exceptionally safe programs.

Because Rust has a rich and strong type system and a deeper, stricter compiler, programming is challenging for a beginner, but if code compiles, it probably works! This teaches us delayed gratification: at the beginning it’s difficult and slow; over time, it’s an enjoyable process, and we have fewer bugs to fix, so we are more productive.

It’s a low and high-level language

I love that Rust gives you a sweet balance between capability and abstraction. That is, it’s both a low-level and a high-level language. At the low-level, you get things like:

  • Raw memory pointers (though for advanced programmers, as this breaks safety guarantees.)
  • Can run embedded
  • Compiles to machine code. No intermediaries overhead.
  • Customizable memory Drop

On the high-level side, you get things like:

  • Automatic memory Drop
  • Functional patterns (e.g., iterators, combinators, pattern-matching)
  • Traits (similar to interfaces)
  • Easy multi-threading libraries
  • Memory safety
  • Hygienic macros meta-programming (to extend the syntax of the language at will)

The language has nice abstractions because it learns from other languages, especially the functional ones. You can write elegant, concise code that does complicated stuff. Rust is an eclectic language.

It’s fast

Compared to C, Rust is about 10 percent slower, similarly to C++, and much faster than other languages like Java. Why not use C if you want performance, then? Because apart from being the king of speed, it’s also the king of bugs! In the case of other popular languages like Python, Rust programs run up to 20 times faster, according to the Programming Language Benchmark.

The speed of Rust comes from having a good optimizer, compiling to native code, and many zero-cost abstractions, like iterators, which give the developer sweet syntax for free. No runtime costs are implied.

The garbage collector is garbage

One exciting and special way Rust achieves its speed and reliability is by ditching the garbage collector. This helps in two ways: more speed and more reliability. This is because when you have a garbage collector, you don’t have guarantees of whether the memory will be freed. When it is freed, it happens at a random time. In addition, the garbage collector is an extra program that has to stop your code, do the cleaning, and then continue. Rust is able to remove the GC by using stricter rules about the lifetime of data and how to drop memory. In Rust, memory is dropped when a variable goes out of scope. If you need something different, you need to tell that to the compiler through a thing called lifetime annotations. This makes you aware of how data lives through your program’s execution.

It has excellent tools

Apart from the abstractions, Rust comes with great tools that give you a modern and well-integrated experience while working on a project.

When working with Rust, you usually use Cargo, its project manager, which is well-designed, has many features, and can be extended easily. Cargo helps you create a new project, manage compilation targets, run tests, generate documentation, and so on.

Thanks to the type system and thorough compiler, editors give awesome hints while coding. There are advanced plugins for the most popular IDEs, like the Rust plugin for JetBrains IDEs, and RustAnalyzer for Visual Studio Code and NeoVim. In terms of code quality and standards, you get easy, automated formatting with rustfmt and extra linting with Clippy. This leaves out any potential dispute about style out so that you can stay friends with your coworkers! Another cool thing is that Rust code plays nicely with GitHub copilot and other AI autocompletion tools, so much of the verbosity of the language or boilerplate doesn’t need to be typed if you are OK with some AI code, of course.

The Rust community is great and growing a lot. Because of that, it’s easy to find help online, in official forums, Discord servers, and documentation. And the core team developing the language delivers significant enhancements every couple of months. Another exciting thing is that, even with this fast-paced evolution of the language, you don’t have problems with compatibility between versions. Rust guarantees the compatibility of a project with dependencies that run an older or newer version of the compiler. That removes a lot of the hassle of dependency management.

It’s versatile

Though Rust is known as a language for writing systems software only, it’s actually more versatile and general-purpose. It can compile to embedded devices, to x86, ARM, and thanks to technologies like WebAssembly, Rust can be used for front-end development in a browser. The ecosystem is growing, and Rust is used for things like games, microservices, front-end, blockchain, CLIs, GUIs, and so on.

All these aspects infatuate developers, which is a key factor because when you love what you do and how you do it, you become more productive and careful with the quality of what you deliver.

Cool stuff is being made with Rust!

Due to the industry’s need for a programming language like Rust in the industry, and its cool features, big companies have started using it. Among them are Meta, Microsoft, Google, Amazon, Mozilla, JFrog, and now even Infobip!

Apart from that, important projects are embracing the language. Among the most notable is the Linux kernel. After more than 30 years, they finally convinced Linus Torvalds to include a second language, apart from C, to develop the kernel. That speaks about the language!

Apart from that, a lot of interesting projects have been started to enhance the safety and speed of the overall software industry. Some of them are Dino, the evolution of Node.js, and WASI, which allows you to run general programs in WebAssembly with access to operating system resources. Cloud-native systems are starting to benefit a lot from the minimal performance impact and safety that WebAssembly and WASI bring to the table.

Rust is also well suited for blockchain systems, and many of them use it, including Solana and DFinity’s Internet Computer. Another factor contributing to loving Rust is that you get to work on cool projects!

How Rust achieves safety

The primary way in which Rust achieves safety is by giving your code more order. In other languages, for example, you could have a variable passed as a reference to different functions, which can modify its value. That may have side effects because you could have multiple functions writing and several others reading, which may cause difficult-to-track bugs. In contrast, Rust is strict in how you can pass values to functions, so they aren’t written by multiple functions. It also promotes immutability, which means the language itself prefers you to have values that cannot be changed, to remove nasty surprises.

Another way in which Rust achieves safer software is by making you aware of what can fail. You must handle the cases of failure. Otherwise, your code looks ugly, with many unwraps(). When a function can fail, you must be explicit about handling the case of success and the possibility of failure by wrapping the Result of that function in a Result<T, E> enum. That enum has two possible elements, a success type, and a failure type. This is just like a Schroedinger box! If you had a function to buy a cat online, the cat might arrive just fine, or it might be dead. In Rust, you must write code to handle the two cases, you become aware, which makes your program more robust.

A brighter future

The reason I like to advocate for Rust is that I believe that it presents a real opportunity for the software industry in general to improve. We can have a safer and faster world of computing. This opportunity comes from the context it has. Mainly, Rust is relevant because it comes with excellent tools and a modern experience, which makes more people use it. The language also offers unique benefits that are very valuable to the industry. In the past, we had other languages with similar offers, but they didn’t have the characteristics that may make Rust a dominant language in the future. For example, we had C, which is a bit faster but very error-prone. We had Haskell, which has nicer abstractions but never got widely adopted and doesn’t have the same ecosystem of tools. We had others like APL, which had much cleaner syntax but were difficult to read and didn’t have a big community. We even had other possibly safer languages like SPARK Ada. Still, the same problems haunt them: they don’t have good adoption, they don’t have the same performance, they don’t have a great ecosystem of tools, and there’s a tiny community behind them.

How to use Infobip’s communication channels with Rust

We recently added the Infobip API Rust SDK, which enables you to use Rust if you have a use case for communication channels! (e.g., WhatsApp, Email, SMS) You can get access to all the coolness mentioned above! See What aspects go into a good Rust library to get some ideas of what this SDK does for you. If you are interested in learning Rust, you can check the code in our GitHub repository, where you are welcome to send PRs and suggest improvements.

Thanks for reading!