一、下载
到官网https://www.rust-lang.org/zh-CN/tools/install下载你需要的版本
二、安装
执行rustup-init 文件,选择1
按提示直到安装完成
可以通过以下命令测试:
rustc -V # 注意的大写的 V
cargo -V # 注意的大写的 V
三、在VScode中调试
创建.vscode文件夹,目录结构如下
并依次创建tasks.json
{"version": "2.0.0","tasks": [{"label": "build","type": "shell","command": "cargo","args": ["build"]}]
}
和launch.json
{"version": "0.2.0","configurations": [{"name": "(Windows)启动","preLaunchTask": "build","type": "cppvsdbg","request": "launch","program": "${workspaceFolder}/target/debug/${workspaceFolderBasename}.exe","args": [],"stopAtEntry": false,"cwd": "${workspaceFolder}","environment": [],"externalConsole": false},{"name": "(gdb)启动","type": "cppdbg","request": "launch","program": "${workspaceFolder}/target/debug/${workspaceFolderBasename}.exe","args": [],"stopAtEntry": false,"cwd": "${workspaceFolder}","environment": [],"externalConsole": false,"MIMode": "gdb","miDebuggerPath": "C:\\Program Files\\MinGW-w64\\bin\\gdb.exe","setupCommands": [{"description": "为gdb启用整齐打印","text": "-enable-pretty-printing","ignoreFailures": true}]}]
}
正常返回src下的main.rs,写入以下代码
fn main() {println!("Hello, world!");
}
然后点击 VSCode 左栏的 "运行"或者在main.rs中按F5。
3.1 (Windows) 启动
如果你使用的是 MSVC 选择 “(Windows) 启动”,它会跳到终端显示执行情况
要手动切换到调试控制台看结果
打断点有效
如果弹出cppvsdbg不受支持,请先安装以下扩展
修改代码后,执行此调试方式,会重新构建,代码生效
3.2 (gdb) 启动
如果使用的是 MinGW 且安装了 GDB 选择"(gdb)启动",gdb 启动前请注意填写 launch.json 中的 “miDebuggerPath”。
先下载MinGW64 8.1 (https://www.onlinedown.net/soft/10045442.htm)到电脑上,解压后路径填到launch.json 中的miDebuggerPath。
按F5后,直接在终端看结果。
打断点无效
修改代码后,执行此调试方式,不会重新构建,代码不生效