I have been exploring Rust from the last few weeks, as it has been declared the most loving language in 2018. As a Scala/Java developer, I worked on many applications, which were related to the banking domain, web applications, mobile applications, e-commerce, social media, etc. But I was not able to find what kind of applications should be built in Rust? I have searched Rust’s good use cases. What I found is that Rust is mainly used for system programming as an alternative of c and c++. I have also checked some job descriptions and most of them are looking for blockchain developer with Rust. I didn’t get any satisfactory answer. I asked below questions with the community and got my answers.
- Why I should switch to Rust, if I am from Scala/Java background?
- What kind of applications should be built in Rust?
- Why blockchain applications need Rust?
- Should I convert my c/c++ application in Rust?
- Is there any popular application, built on Rust?
If we talk about the precise use cases, like Java for Web apps, python for data science, the equivalent of that in Rust is
Systems Programming. Things like Browser engines, game engines, operating systems, software for microcontrollers. Or in other words, basically, the things C and C++ are used for, that you wouldn’t really want to switch to a language like Python, are good use cases for Rust.
But that doesn’t really mean it’s exclusive to these things only. Rust may solidly beat in any other area for performance. Let’s take a look at some popular applications, which are using Rust.
- It is proving to be a great fit for cloud services. Microsoft is using Rust for part of their IoT offerings: https://github.com/Azure/iotedge/tree/master/edgelet .
- Amazon is using Rust to power various parts of their AWS offerings through Firecracker.
- On the customer side, Rust has been used with great success on AWS, including parsing logs so fast the work is done on the free tier of AWS Lambda.
- The Firefox browser is a canonical example.
- The VSCode editor ships with file search written in Rust.
- Full-fledged blockchain protocol- https://github.com/purpleprotocol/purple https://purpleprotocol.org/
Earlier I thought most of the Blockchain applications have started using Rust because Bitcoin was written in C++ and at that moment C++ was the most performant programming language that was out there and blockchains truly need every ounce of performance available. But the fact is some Rust features like high performance, no runtime, and enhanced safety make it attractive in that domain. Rust’s memory and data race safety make it a good fit where one would hesitate to use C or C++, such as publicly available Web services.
Now more important, as a Scala/Java developer, why you should try Rust. Here are the reasons:
- Predictable performance and low memory usage:- In Scala, you have to spend a lot of times on trying to implement optimizers, value classes and specialization in the Scala compiler. In Rust you basically don’t have to worry about this, everything is optimized as far as possible.
- Concurrency:- Rust won’t compile most concurrency bugs.
- No null pointer exceptions:- There’s a possibility that a null value can sneak into your program from a Java library or elsewhere. That is not the case in Rust.
- Minimal type system:- there are no classes, no inheritance, no singleton objects, no implicits etc., just ADT’s, traits and functions basically.
- No GC, i.e. full control over data lifetimes, predictable and low memory usage, and no runtime pauses
- No VM, just lean and mean native applications
- Rust normally has no shared mutability so threading is also surprisingly nice in Rust.
- Pure-Rust dependencies are statically linked by default so you can use created binaries and libraries without installing Rust everywhere.
As per my research, I believe Rust can be fit anywhere and you should start playing with it. I hope you enjoy reading this blog. Thanks!