1. 中文官网
rust中文官网: https://www.rust-lang.org/zh-CN
2. 必须先安装的软件
- 下载 RUSTUP-INIT.EXE(64位)
- 安装vscode,安装rust扩展
- 必须安装辅助编译的软件 (VISUAL STUDIO 2017)https://www.visualstudio.com/downloads/[] 或者 (Microsoft Visual C++ Build Tools 2015)[http://go.microsoft.com/fwlink/?LinkId=691126] 二选一
3. 配置环境变量
- 在 Rust 开发环境中,所有工具都安装在
~/.cargo/bin目录中,您可以在这里找到包括rustc、cargo和rustup在内的 Rust 工具链。 - 将
~/.cargo/bin目录加入环境变量PATH中4. 安装Rust辅助工具
4.1切换国内rust源
C:\Users\xxxx\.cargo\文件夹下新建一个文件config- 文件内容填入以下内容,配置清华的源 ``` [source.crates-io] replace-with = ‘tuna’
[source.tuna] registry = “https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git“
<a name="NyMbm"></a>### 4.2 安装Rust辅助工具
cargo install racer
由于以下工具默认安装里存在占位程序,需要使用 —force 选项强制安装
cargo install —force rustfmt cargo install —force rls
```rustup component add rls-previewrustup component add rust-analysisrustup component add rust-src
5. 安装VSCODE和插件
5.1 安装vscode插件
- Rust(rls)
在 VSCode 中设置 rust-client.channel 为 stable。
同时建议设置 editor.formatOnSave 为 true,以便在保存时使用 rust-fmt 格式化代码。
此时vscode已经可以编写rust文件了, rustc 或者 cargo build 也可以编译rust源码了
或者直接用 cargo run 编译+运行一起执行
下面说下如何让vscode能够调试rust程序
6. VSCode支持Rust程序调试
6.1 安装vscode插件
- windows安装: C/C++插件
- linux和mac安装: CodeLLDB插件
6.2 Rust项目创建launch.json文件
- 在vscode中左侧调试卡片页,选中
create a launch.json file

- 然后根据平台选择: windows选择
C++(Windows),linux和mac选择C++(GDB/LLDB)

- 这时就会会在项目中生成一个
launch.json文件, 修改其中的program项{"name": "(Windows) 启动","type": "cppvsdbg","request": "launch","program": "${workspaceFolder}/target/debug/${workspaceFolderBasename}.exe","args": [],"stopAtEntry": false,"cwd": "${workspaceFolder}","environment": [],"externalConsole": false}
6.3 修改系统配置
- 然后在
File->Preferences->Settings->Features->Debug中的Allow setting breakpoints in any file选项上打勾

6.4 开始调试
- 现在就可以按
F5开始调试了 - 由于Rust是编译语言,所以每次修改代码之后,需要先编译(
ctrl+shift+B一键编译)再调试(F5)
