banner
zam

zam

君子可内敛而不可懦弱,面不公可起而论之。
twitter
telegram
github

Rust Records Day01

Day01#

Understanding the History of Rust#

Interesting Development Experience#

One day in 2006, after working tirelessly, the author wanted to go back to his apartment and enjoy life. However, he discovered that the elevator program had crashed due to a bug. You see, in foreign countries, repairmen are not readily available like they are in China, and to make matters worse, his apartment was on the 20th floor! In the end, he had to compromise and stay in a hotel for a few days while waiting for the elevator to be repaired.

Of course, most people would just accept the situation and wait for a few days to pass. But this extraordinary programmer was not an ordinary person. He picked up his sword - Rust - to slay the dragon that had caused him to be displaced.

And thus, a whole new programming world was opened up.

Efficiency of Rust#

Learning Efficiency#

It can be said that the learning curve of Rust is steep.

The difficulty of Rust does not lie in its language features, as they can be easily learned. The real challenge lies in:

  • How to apply what you have learned in practice
  • How to quickly and correctly solve problems when encountering pitfalls (such as lifetimes, borrowing errors, self-referential structs, etc.)
  • Memorizing and proficiently using a large number of standard library methods, which is crucial for development efficiency
    It can be mentally burdensome, especially in the intermediate stage.
Runtime Efficiency#

Thanks to its zero-cost abstractions, potential for low-level optimizations, high-quality standard library, and third-party library implementations, Rust has excellent performance on par with C and C++.

Furthermore, Rust has a great advantage: as long as it is used correctly, it can achieve excellent performance without the need for manual optimizations. It is truly impressive.

Development Efficiency#

The development efficiency of Rust can be described as starting slow and then gaining momentum.

Once you become familiar with various standard libraries, lifetimes, and common solutions for ownership, and even develop muscle memory, your development efficiency will greatly improve, and you will be able to write high-quality native code.

Summary#

Being the most popular language for six consecutive years is not just an empty reputation. Rust's unique features and strengths, such as no garbage collection, high efficiency, strong engineering capabilities, strong safety, and recognition from both the engineering and academic communities, have given it its own distinct characteristics and space for development. The friendly community, rapid growth of the ecosystem, and support from major companies all indicate a bright future for Rust.

Advice for the Learning Process#

  • Be prepared for difficulties in advance, as learning Rust is not just about learning a programming language.
  • Don't approach it with a "let's give it a try" mentality, as it would waste time and diminish your enthusiasm for learning. Rust, as the language that has been voted the most loved language worldwide for seven consecutive years, is more than just worth a try :)
  • Dive deep into a good book or tutorial.

After overcoming countless challenges, you will become a great developer. (Haha😀, the author is really funny)

Installation and Configuration of Rust#

Installation on Windows#

Since I personally use a Windows system, I will only provide instructions for installing Rust on Windows, and it may not be the standard method.

Installing Rust on Windows requires a C++ environment, and there are two ways to install it:

1. x86_64-pc-windows-msvc (official recommendation)

First, install "Microsoft C++ Build Tools" and select the option to install the C++ environment. You can modify the cache path and installation path as desired during the installation. After the installation is complete, the msvc command-line program required by Rust needs to be manually added to the environment variables. Otherwise, when installing Rust using rustup-init, it will prompt that Microsoft C++ Build Tools are not installed. The program is located at: %Visual Studio installation path%\VC\Tools\MSVC\%version%\bin\Hostx64\x64 (please replace %Visual Studio installation path% and %version% with the appropriate values).

If you don't want to do this, you can choose to install the "Custom" terminal added by Microsoft C++ Build Tools, such as "Developer Command Prompt for %Visual Studio version%" or "Developer PowerShell for %Visual Studio version%", and run rustup-init.exe in it.

Once you have prepared the C++ environment, you can start installing Rust:

Download the Rust installation program corresponding to your system from RUSTUP-INIT and proceed with the default options.

PS C:\Users\Hehongyuan> rustup-init.exe
......
Current installation options:

   default host triple: x86_64-pc-windows-msvc
     default toolchain: stable (default)
               profile: default
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation

Linux#

For the Linux environment, I set up a virtual environment using VMware virtual machine, and the disk image was provided by the "rCore-Tutorial-Book-v3" experimental document, which already had Rust and C language environments fully configured. Therefore, I am not familiar with the installation process. If necessary, I will learn it in the future.

Updating and Uninstalling#

Check if the installation was successful:

$ rustc -V
rustc 1.72.1 (d5c2e9c34 2023-09-13)
$ cargo -V
rustc 1.72.1 (d5c2e9c34 2023-09-13)

Updating:

$ rustup update

Uninstalling:

$ rustup self uninstall

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.