Rust has been rated the most wanted programming language on Stack Overflow for five consecutive years and has been well received.
The following part is my experience. At the same time, I will discuss the feasibility of Rust in combination with my daily work.
Microsoft has published an article called Microsoft: Rust Is the Industry's 'Best Chance' at Safe Systems Programming. It made one thing clear. The cloud is an industrial-grade product, and an industrial-grade safety system is needed. Safety here refers to Memory Safe, Type Safe, and Thread Safe in software development to ensure product stability.
We know after the release of new products, the tasks in the next period are mainly bug fixing. These bugs are usually not business bugs but code bugs caused by improper concurrency control, such as memory overflow, null pointers, and data errors. It is difficult for these bugs to be found by tests. If a good development language can help eliminate many potential problems in this area, is it very good?
Don't worry about performance because Rust is as fast as C and C++.
I agree with the viewpoint in this article that Rust is a very good infrastructure language for cloud product development. It guarantees stability. Everyone says the Internet focuses on cloud products. However, the key customers of cloud vendors are enterprise customers. Therefore, stability assurance comes first. Enterprises may use their businesses to try out cloud products.
Another piece of news comes from the article entitled Programming languages: Now Rust project looks for a way into the Linux kernel. In other words, the Linux kernel may embrace Rust, and Linus Torvalds has already recognized Rust.
The advantages of using Rust to develop infrastructure cloud products will not be described here, but the performance is high, and the stability is good.
If we cannot develop products with Rust, does that mean ordinary programmers cannot use Rust? No. There is a product here.
Rust SDK development: Many cloud vendors have developed their middleware products based on Java and C++. Therefore, we need to develop SDKs that do not depend on programming languages, such as Java SDKs and Python SDKs.
Is there any difference in Rust SDK for products? I'll explain it to you here. Let's take Alibaba Dubbo as an example. If you do not know Dubbo, you can regard it as a distributed RPC call framework. Dubbo Rust SDK has the following features:
If the customer's system was originally developed using Rust, there should be nothing to refute this requirement for accessing Dubbo services through Rust, right? Rust Web framework Actix-web ranks high in performance tests. Dubbo Rust SDK, especially in I/O and network, is implemented through Tokio. So, asynchronization is supported by default, and performance is also very high.
Wait a minute. Is it so simple to write an SDK involving network calls?
The use of Tokio still involves a lot of work and is not so easy to write. In theory, this is the case. However, if you look at the tutorial of Tokio 0.2.22, you will find it very simple! This tutorial will not tell you how to write an Echo Server and Client but how to implement a Mini Redis. Complete documentation and code samples are available. You need to make some adjustments to preliminarily implement the functions of Rust SDK.
We know Rust is the current preferred language of WebAssembly. Let's say you want to access Dubbo services in WebAssembly, such as in a browser. We only need to adapt to WebSocket and run the environment in WebAssembly. This way, we can access Dubbo services through WebSocket. The Rust SDK for Wasm virtually shares the Rust SDK code and makes some modifications.
WebAssembly also serves as the Universal Library, which can be understood if you have learned the wasmtime demo.
There are many Node.js developers, but it is not easy to use C++ to develop a Node.js extension. A very small number of developers have this ability. Is it complicated to develop a Deno Rust plugin? No, it is very simple. You only need to refer to the Calcite framework, which has very good documents and samples. At the same time, you can combine it with the development kit on Crates.io. It is very simple to develop a high-quality Deno Rust plugin.
How is the C language supported to access Dubbo? Let's say some C programs of ARM devices want to access Dubbo services. We can export the cdylib library through Rust FFI and provide it for C language calls, eliminating the cost of developing the C SDK. This cost is not low. I also wanted to write a C SDK for RSocket previously, but I gave up after careful consideration. Now, I plan to provide an access interface for the C language through Rust SDK. If it works, it may be possible for other niche languages based on C to access Dubbo services, such as Lua.
As mentioned above, Rust SDK provides a corresponding SDK for the C language through FFI. The same principle can be applied to other languages, such as Calling Rust from Python. There are many cases on the Internet. It is the same for Ruby. Is there any corresponding case for Java? Yes, the java-ext-wasm project. The WebAssembly Runtime environment is embedded into JVM to run WebAssembly. This WebAssembly Runtime is written in Rust.
It would be impossible to compare C++ and Rust in developer experience. Features, such as the consistency among Linux, Windows, and Mac platforms of Rust, are far better than C++. Rust has Crates.io, which is not available for C++.
Currently, one of the bad developer experiences in Rust is that the compilation speed is too slow. The compiler has done a lot of work, but there seems to be only Shared Compilation Cache (sccache) that can improve the compilation speed. I haven't used this yet. Perhaps, my project is not big enough. I haven't encountered a very slow compilation speed, and the speed is acceptable. The Rust community is also discussing pre-built dependency, which may take some time.
At this point, some of you must want to try to learn and understand Rust. Is the learning cost high? I think it should be seen from several aspects.
Among all the development languages, the documents of Rust are the best. The Rust website provides The Rust Programming Language, which can be called the best learning book. It is completely free and updated frequently. I think the quality is comparable to Programming Ruby of the Pragmatic Bookshelf. Rust is free and often updated. There are also other high-quality Rust-related documents, such as Rust By Example and Rust WebAssembly.
In addition, you will understand if you look at the Rust Cheat Sheet.
Other languages also have corresponding documents, but I would like to ask how many Java developers learn Java in Oracle Java? Rust does a different job. All the learning documents are first-class so you can learn without pressure.
I was really confused at first. I think Clear explanation of Rust's module system is very good. You will see after reading it!
Those learning about this recently may feel frustrated. At least, I am. This is also a feature of Rust. Without GC, it has to choose an unusual path to achieve the same effect as GC. However, it's not so frustrating. You can read some articles about Rust Ownership to understand more. In addition, I recommend this site. This man's Rust videos are very good and very easy to understand, and there are many materials. I believe you will understand it when you watch his videos and read his documents. You only need one good guide.
Rust Enum is very powerful, which should be paid special attention to. I think Swift Enum can compete with Rust Enum. Results and Optional commonly seen in other languages are implemented through Enum in Rust.
I won't talk about other features of Rust since other languages have them as well. Here is a description of Tokio.
These are the conclusions from the individual learning of Deno and the writing of some Rust demos. This article explains the topic somewhat and may not be comprehensive. It's just for reference.
Finally, when learning a language, don't listen to any language master. I say read the documents yourself, write demos, view the code of some well-known open-source software, and draw your own conclusions.
OpenAnolis - March 7, 2022
feuyeux - May 8, 2021
Alibaba Cloud Community - June 6, 2022
Adrian Peng - February 1, 2021
Alibaba Cloud Community - March 9, 2022
Alibaba Developer - October 25, 2019
Explore Web Hosting solutions that can power your personal website or empower your online business.Learn More
Explore how our Web Hosting solutions help small and medium sized companies power their websites and online businesses.Learn More
Web App Service allows you to deploy, scale, adjust, and monitor applications in an easy, efficient, secure, and flexible manner.Learn More
A cloud firewall service utilizing big data capabilities to protect against web-based attacksLearn More
More Posts by Alibaba Cloud Community