Rust supports many integrated development environments (ides) or development-specific text editors. Check out the official website for supported development tools.

Rust’s compilation tools rely on C compilation tools, which can be used with Microsoft C++ generation tools or the MinGW + GCC compilation environment.

This article uses Microsoft C++ generation tools + Visual Studio Code.

Install Microsoft C++ generation tools

The Microsoft C++ generation tool primarily provides a C compilation environment for Rust, which is a separate installable component of Visual Studio. If you have Visual Studio 2013 or later installed on your system and the Microsoft C++ builder is checked during installation, there is no need to install an additional Microsoft C++ builder.

Download the Microsoft C++ builder.

Double-click the downloaded installation packagevs_buildtools__xxx.xxxIn the window that pops up, check [C++ builder] and English language package, and then click [install].

Install rustup

Rustup is Rust’s installation and management tool, and by default, it installs these tools at the same time: RUstC, rust-STD, Cargo, Rust-Docs, RustFMT, Clippy. Of these, RUSTC is Rust’s compilation tool and Cargo is Rust’s package management tool.

Download RUSTUP – INIT. EXE.

Double-click downloadedRUSTUP-INIT.EXE, if the OPERATING system does not have a C language compilation environment, a message will be displayed in the CMD window (see the red characters in the following figure).

Double-click downloadedRUSTUP-INIT.EXEIf it has been installedMicrosoft C++ generation toolThe following content is displayed. Just hit Enter, because the default C compiler is MSVC.If you want to useMinGW + GCCTo compile the environment, enter 2 for custom installation (MinGW needs to be installed in advance).

Successful installation: Press Enter. The installation is complete.

confirm: Open a new CMD window and enterrustc --versionandcargo --versionCommand.

Install VSCode and related plug-ins

To start, install Visual Studio Code, and then install the following plug-ins in VSCode:

  • Rust-analyzer /Rust Support for Visual Studio Code – Provides Code completion, Code jump, formatting, and more (just install one of them).
  • TabNine – Artificial intelligence code prompt plugin, very useful.
  • C/C++ for Visual Studio Code or CodeLLDB — Debug
  • TOML support for vscode

Configure the domestic Crate source

When building a Rust project, the Cargo tool gets the project dependency package (Crate) from “Registry”, which is crates. IO by default. However, accessing this site in China is usually slow, so we can replace it with the domestic Crate source.

Configuration method: Add the following contents to the $HOME/.cargo/config file

[source.crates-io]
replace-with = 'ustc'

[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"
Copy the code

The first Rust program

Create a new rust_demo folder and open it with VSCode. Create a new terminal in VSCode and type the following command:

#Create a package called HelloWorld (project)
cargo new helloworld
#Enter the helloWorld folder
cd .\helloworld\
#build
cargo build
#Run (Build before Run)
cargo run
Copy the code

Problems you might encounter

The program is blocked while running

Prompt message:

PS F:\rust-demo> cd .\guessing_game\
PS F:\rust-demo\guessing_game> cargo run
    Blocking waiting for file lock on package cache
Copy the code

Solutions:

Delete the ~/.cargo/.package-cache file if you are sure there are no more programs occupying it.

Failed to download Crate after modifying the image. Procedure

Error message:

PS F:\rust-demo\guessing_game> cargo build
    Updating `git://mirrors.ustc.edu.cn/crates.io-index` index
warning: spurious network error (2 tries remaining): [35] SSL connect error (schannel: next InitializeSecurityContext failed: Unknown error (0x80092013) - ���ڵ������������ѻ������������޷���������)
warning: spurious network error (2 tries remaining): [35] SSL connect error (schannel: next InitializeSecurityContext failed: Unknown error (0x80092013) - ���ڵ������������ѻ������������޷���������)
warning: spurious network error (2 tries remaining): [35] SSL connect error (schannel: next InitializeSecurityContext failed: Unknown error (0x80092013) - ���ڵ������������ѻ������������޷���������)
warning: spurious network error (2 tries remaining): [35] SSL connect error (schannel: next InitializeSecurityContext failed: Unknown error (0x80092013) - ���ڵ������������ѻ������������޷���������)
warning: spurious network error (1 tries remaining): [35] SSL connect error (schannel: next InitializeSecurityContext failed: Unknown error (0x80092013) - ���ڵ������������ѻ������������޷���������)
warning: spurious network error (1 tries remaining): [35] SSL connect error (schannel: next InitializeSecurityContext failed: Unknown error (0x80092013) - ���ڵ������������ѻ������������޷���������)
warning: spurious network error (1 tries remaining): [35] SSL connect error (schannel: next InitializeSecurityContext failed
Copy the code

Solutions:

Add the following to the ~/.cargo/config file

[http]
check-revoke = false
Copy the code

The relevant data

The Rust Programming Language

Install Rust

Rust environment construction

Source Replacement – The Cargo Book

Rust Crates source uses help