In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "Why you choose Rust". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "Why choose Rust"!
Why choose Rust?
There are countless programming languages in the world, with 273 included in the TIOBE (Development languages rankings) alone. Here are the top 20 most popular programming languages.
These excellent programming languages often have their own unique skills, such as C performance is very high, Java is easy to abstract and good at organizing large programs, Python is suitable for small scripts, and so on. But again, they are not perfect, high-performance C is prone to segment errors (segfault, crashes caused by accessing memory that does not belong to the program, such as empty pointer dereference, etc.), Java that is good at abstraction requires garbage collection (GC), and Python interpretation that is fast to use is slow to execute. Therefore, there is still room for progress in the design and development of programming languages, and Rust is a new generation that has emerged in recent years to integrate the advantages of major programming languages.
The designers of Rust positioned the language as follows:
Rust is a system's programming language that runs blazingly fast, prevents segfaults, and guarantees thread safety.
The outstanding advantages of Rust can be summed up in the following three points (you don't need to understand, just know that Rust is good):
Memory security: the most important feature of Rust is that it can provide memory security without additional performance loss. To ensure memory security, that is, there will be no memory access errors, Rust has established a strict memory security management model:
Ownership system: each allocated memory has a pointer with exclusive ownership, and only when the pointer is destroyed can the corresponding memory be released. The ownership system borrows from C++ 's RAII mechanism, which is the cornerstone of Rust without GC but can safely manage memory.
Borrowing and lifecycle: each variable has its own life cycle, and once the life cycle is exceeded, the variable is automatically released. If borrowed, you can prevent dangling pointers, which are used after release, by marking the lifecycle parameters for the compiler to check.
Zero-cost abstraction: abstract expression ability is a necessary condition for efficient development using programming languages. The abstract expression ability of some languages is acquired at the expense of performance, while the abstract expression ability of Rust does not have runtime performance overhead. The cornerstones of Rust zero-cost abstraction are generics and trait.
Concurrency: both memory-safe bug and concurrency-safe bug are caused by improper access to memory, so using a powerful type system loaded with ownership, Rust can detect data competition in multithreaded concurrent code at compile time.
Rust has been a popular programming language among programmers for many years because of its unique charm. Although it is not in the forefront of the list of TIOBE at present, the Internet must pay more attention to security and high performance in the future, so Rust which arises at the historic moment will have a bright future.
Before we learn the grammar of Rust, let's take a look at the surrounding knowledge of Rust.
Common websites of Rust
Official website: click here. You can find many important contents such as the official textbook TRPL here, so it is helpful to explore this website.
The compiler is open source: click here. For the Rust language, the open source community is also part of the language, which distinguishes it from other commercial languages.
Language design and related discussions: click here. Every time an important language feature is added to Rust, it will go through the standard RFC process. RFC document is a complete technical solution that covers the design intention, detailed design, advantages and disadvantages of the language features. For us learners, we can read RFC to gain an in-depth understanding of the context of a language feature, which will be an extremely valuable learning resource to help understand the principles behind a feature.
Official open source repository: click here. The site stores the popular open source libraries of the Rust community.
Version and release strategy
The version number of the Rust compiler adopts the scheme of semantic version number (Semantic Versioning). The version format is: major version number. The second edition number. The revision number, whose increment rules are as follows:
Major version number: as an incompatible API modification
Minor version number: as a backward compatible functionality addition
Revision number: as a backward compatible issue correction
The Rust team maintains three release branches:
Development version (nightly): the latest features will first be released in this branch for users to try out.
Beta (beta): make the features verified in the nightly version open to users and can be seen as a pre-release version of the stable version.
Stable version (stable): a stable and reliable version released every 6 weeks.
For every relatively complex new feature of the Rust language, you have to go through the following steps to be truly stable and available:
RFC-> Nightly-> Beta-> Stable
Sometimes some new features do need to break compatibility to a certain extent, in order to minimize the impact of these changes on users, the Rust design team also proposed a so-called edition solution, there are 2015 and 2018 kinds of edition, we can set "edition=2018" to tell the compiler which version we are using.
Install the development environment
According to the recommendation of the official website, you can use a tool called rustup to install a complete set of tool chains related to Rust. The command is as follows:
Curl-- proto'= https'-- tlsv1.2-sSf https://sh.rustup.rs | sh
We can use the rustup tool to manage the tool chain:
/ / Update rustup itself rustup self update// update tool chain rustup update
You can also use it to easily switch between the three versions of stable/beta/nightly:
/ / install the nightly version of the tool chain rustup install nightly// setting the default tool chain is nightly version rustup default nightly
If you can correctly output the version number by executing the following command, Rust is installed successfully:
Rustc-version
If the installation is unsuccessful, try adding ~ / .upload / bin to the PATH environment variable.
Some common tools for Rust can be found in the ~ / .tools / bin directory, as shown in the following figure:
Cargo:Rust 's package manager, similar to Python's pip, Node.js 's npm. But cargo is not limited to package management, it also provides a standard workflow for the Rust ecosystem to manage the entire workflow, from creating projects, running unit tests and benchmarks, to building release link libraries, to running executables, and so on.
A compiler for rustc:Rust that compiles Rust source code into executable files or other library files. Rustc is developed by Rust and outputs error messages that are far more friendly and detailed than any compiler you've ever seen.
Rustdoc: document generator.
Rls and racer: code hints for editors.
Cargo-fmt and rustfmt: source code formatting tools, with this, you no longer have to argue whether the curly braces should be written at the end of the line or on another line.
Rust-gdb and rust-lldb: debugger.
For IDE,Rust, there is no proprietary IDE yet, and I recommend the Clion+Rust plug-in, which is already very easy to use.
Hello World
With the development environment configured, how can you not write a ceremonial Hello World program? To create a new file named hello_world.rs, the contents are as follows:
/ / hello_world.rsfn main () {let s = "hello world!"; println! ("{}", s);}
Then compile it with rustc, and you can see that an executable program named hello_world is generated under the current folder:
At this point, I believe you have a deeper understanding of "Why choose Rust", might as well come to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.