The first lesson of Ca weekly in 2022 – rust

Time:2022-4-24

There are many modern programming languages. In my programming study, there are logo in primary school, Pascal in middle school, and C / C + +, Java and Net, and then to Objective-C, swift, go, kotlin, and rust. In 2021, after the 4-month artificial intelligence course, I was thinking about what skills can be brought to reactor’s partners. I have thought about whether it is a cool product on our three clouds or the practice of some solutions. After weighing, I decided to bring rust to you as a new beginning of 2022.

Why rust?

I don’t know when, every language is born with its own high performance, reliability and productivity. And when you really go into the pit, there will always be all kinds of complaints. I know that rust was introduced by Yi Mingzhi three years ago. I forgot how he was Amway, but I stepped into the pit.

Rust’s syntax is very similar to C + +, with high speed and memory security. Rust is a system level programming language.
Let’s take a look at some memory security comparisons between rust and C / C + +:

int checkStr()
 {
char *str = strdup("Hello Reactor!"); 
return 0;                            
 }

In C / C + +, the above syntax forgets to release the pointer, resulting in memory leakage, which is a very basic problem. But in rust, we can avoid the same problem through scope.

fn checkStr(){
     let str = String::from("Hello Reactor!");
}  

In terms of memory security alone, rust is easy enough to use. In addition, rust can manage related packages through Crites. The whole project code cycle from project establishment, construction to testing, and then to running and deployment is really comfortable compared with the chaos in C / C + + development.

What tools are used to develop rust?

A good tool can improve the efficiency of development. Developing rust, I still strongly recommend video studio code. It has very perfect rust support. Just install the three plug-ins of trust analyzer, codelldb and Crites, and you can complete the development of rust very efficiently.
The first lesson of Ca weekly in 2022 - rust

I also used another way in class – jupyter notebook. Through notebook, you can complete some related grammar learning and do some data analysis.
The first lesson of Ca weekly in 2022 - rust

After class, some friends asked me how to install it. Here I attach the installation steps.

Python environment installation and basic jupyter lab installation

Please refer to my previous documentation

Windows installation

Linux / MacOS installation

Component installation

cargo install evcxr_jupyter
evcxr_jupyter –install

Note: there are different system configuration requirements here. Please refer to:https://github.com/google/evcxr/blob/main/evcxr_jupyter/README.md

Application of rust

Rust has a wide range of application scenarios. Based on its own characteristics, it is often used in some bottom and back-end services and network programming. The official also lists some main application scenarios:
The first lesson of Ca weekly in 2022 - rust

In this series of courses, I mainly introduced the work of Web backend, and of course, I also mentioned web assembly. I suggest you can go back to the second and third lectures of my rust course.

Rust’s Web Framework

Actix and rocket are both very mature rust page service frameworks, which are equal to each other. My course focuses on Actix framework. Of course, you can also try rocket framework.
The following is the introduction of the two frameworks, which can be selected according to the actual situation.
The first lesson of Ca weekly in 2022 - rust

I personally pay more attention to architecture. A good architecture is the beginning of a good project. Doing back-end services is inseparable from the familiar model of MVC. Combined with the knowledge of rust’s package, we can use Actix’s back-end solution to build a very good project. It is suggested that you can refer to the third lecture of my rust course when building rust back-end services.

Omission of course

The three week course is very short, and rust involves many points. For example, how to use dapr and the application of web assembly are also what I want to talk about.
Next, I will continue to share with you through workshop. Please look forward to it!

Finally, three lectures of this series of courses are attached:
Rust programming language – rust basic learning
Rust programming language – rust web programming
Rust programming language – rust network programming & IOT programming