English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Rust supporta molti ambienti di sviluppo integrati (IDE) o editor di testo specifici per lo sviluppo.
The official website announced the following supported tools (https://www.rust-lang.org/zh-CN/tools):
This tutorial will use Visual Studio Code as our development environment (Eclipse has a version specifically for Rust development, which is also a good choice for beginners).
Note: It is difficult to debug after installing the IntelliJ IDEA plugin, so it is recommended that developers who are accustomed to using IDEA use CLion, but CLion is not free.
Firstly, you need to install the latest version of the Rust compilation tool and Visual Studio Code.
Rust compilation tool:https://www.rust-lang.org/zh-CN/tools/install
Visual Studio Code:https://code.visualstudio.com/Download
The Rust compilation tool depends on the C language compilation tool, which means that there is at least one C language compilation environment on your computer. If you are using a Linux system, you often already have GCC or clang. If you are using macOS, you need to install Xcode. If you are using the Windows operating system, you need to install the Visual Studio 2013 or above environment (which requires C/C++ support) to use MSVC or install MinGW + GCC compilation environment (Cygwin has not been tested).
The Rust compilation tool is recommended to use the Rustup installation downloaded from the link above. The downloaded Rustup is an executable program rustup-init.exe on Windows. (It should be rustup-init.sh on other platforms).
Now execute the rustup-init file:
The picture above shows a command line installation wizard.
If you have already installed MSVC (recommended), the installation process will be very simple. Enter 1 and press Enter to directly enter the second step。
If you are installing MinGW, you need to enter 2 (custom installation) and then the system will ask you Default host triple? Please refer to the picture above default host triple Change "msvc" to "gnu" and then enter the installation program:
All other properties are set to default.
After setting all the options, you will return to the installation wizard interface (the first picture), where you can enter 1 and press Enter.
进行到这一步就完成了 Rust 的安装,可以通过以下命令测试:
rustc -V # 注意的大写的 V
如果以上两个命令能够输出你安装的版本号,就是安装成功了。
下载完 Visual Studio Code 安装包之后启动安装向导安装(此步骤不在此赘述)。
安装完 Visual Studio Code (下文简称 VSCode)之后运行 VSCode。
在左边栏里找到 "Extensions",并查找 "Chinese",安装简体中文扩展,使界面变成中文。(如果你愿意用英文界面或计算机不支持中文字符,此步骤可以跳过)。
用同样的方法再安装 rls 和 Native Debug 两个扩展。
重新启动 VSCode,Rust 的开发环境就搭建好了。
现在新建一个文件夹,如 w3codebox-greeting。
在 VSCode 中打开新建的文件夹:
打开文件夹之后选择菜单栏中的"终端"-"新建终端",会打开一个新的终端:
在终端中输入命令:
cargo new greeting
当前文件下下会构建一个名叫 greeting 的 Rust 工程目录。
现在在终端里输入以下三个命令:
cd ./greeting cargo build cargo run
系统在创建工程时会生成一个 Hello, world 源程序 main.rs,这时会被编译并运行:
至此,你成功的构建了一个 Rust 命令行程序!
有关在 VSCode 中调试程序的问题,详见 教程Cargo。