Rust 是一门系统编程语言,专注于安全,尤其是并发安全,支持函数式和命令式以及泛型等编程范式的多范式语言。Rust 在语法上和 C++ 类似 ,设计者想要在保证性能的同时提供更好的内存安全。
目录
[3、安装和配置 RustRover](#3、安装和配置 RustRover)
1、官网下载
进入官网地址

点击 Install 安装
进入安装页面,下载对应版本的安装装程序,笔者是64位 windows系统

点击下载

2、安装Rust
下载Rust暗转程序后,先不要着急安装,先配置 RUSTUP_HOME 和 CARGO_HOME 环境变量,这样可以自定义Rust的安装目录,更加灵活
笔者新建下面目录结构

然后配置环境变量
新建系统变量 RUSTUP_HOME = D:\env\rust\rustup
新建系统变量 CARGO_HOME = D:\env\rust\cargo
编辑系统环境变量 Path ,添加 %CARGO_HOME%\bin

配置完环境变量后,执行 Rust 安装程序,弹出下面窗口

按 回车

输入 1 后按回车
rust 需要 Visual C++ 的环境,如果电脑上没有,会先安装,笔者电脑上没有


点击安装

安装完成 点击 确定

安装完成后,再次点击 rustup-init.exe 进行安装

输入 y 按 回车


输入 1 按 回车

安装完成
重新打开新的 cmd 窗口 输入下面命令查看是否安装成功
bash
rustc --version

如果上面 安装 rust 的过程时间长,下载速度慢,可以配置下面环境变量,修改下载地址为国内镜像
RUSTUP 镜像
RUSTUP_DIST_SERVER = https://rsproxy.cn
RUSTUP_UPDATE_ROOT = https://rsproxy.cn/rustup
或
RUSTUP_DIST_SERVER = https://mirrors.ustc.edu.cn/rust-static
RUSTUP_UPDATE_ROOT = https://mirrors.ustc.edu.cn/rust-static/rustup
3、安装和配置 RustRover
笔者使用 RustRover 开发工具,官网下载 RustRover 并安装
安装完成后,打开编辑器,open一个目作为工作区
打开后,点击Settings,找到 Rust 选项,会自动识别
在工作区目录上右键,New Cargo Create 创建项目

项目创建完成

如果项目创建过程中编译报错,可在cargo的安装目录下 创建 config.toml 文件

config.toml 文件内配置国内镜像
bash
[registry]
default = "crates-io"
[source.crates-io]
replace-with = 'ustc'
[source.ustc]
registry = "sparse+https://mirrors.ustc.edu.cn/crates.io-index/"
[net]
git-fetch-with-cli = true
项目编译完成
运行 Hello World

点击绿色三角运行程序
如果运行遇到下面报错
bash
D:/env/rust/cargo/bin/cargo.exe build --color=always --message-format=json-diagnostic-rendered-ansi --package demo --bin demo
Compiling demo v0.1.0 (D:\rust-workspace\demo)
error: linker `link.exe` not found
|
= note: program not found
note: the msvc targets depend on the msvc linker but `link.exe` was not found
note: please ensure that Visual Studio 2017 or later, or Build Tools for Visual Studio were installed with the Visual C++ option.
note: VS Code is a different product, and is not sufficient.
error: could not compile `demo` (bin "demo") due to 1 previous error
Process finished with exit code 101
则下载 vs_BuildTools,安装 使用 C++ 的桌面开发
下载地址:https://visualstudio.microsoft.com/zh-hans/downloads/#build-tools-for-visual-studio-2022
安装 使用 C++ 的桌面开发

安装后即可解决上面找不到 link.exe 的问题
运行后效果

Rust开发环境搭建完成
至此完