前置依賴
裝過Visual Studio或Visual Studio Build Tool 2015
下載Rust離線安裝包
https://forge.rust-lang.org/other-installation-methods.html
寫本文時使用的版本為1.37
https://static.rust-lang.org/dist/rust-1.37.0-x86_64-pc-windows-msvc.msi
安裝時選Advanced
換下路徑,如
E:\Rust stable MSVC 1.37\
接下來把RLS選項勾上
裝好后到Gayhub下載配置模板節省頭發。
https://github.com/RoteErde/RustVSCodeTemplate
打開VSCode,菜單 File > Open Folder
打開下載的模板目錄
然后VSCode擴展搜Gayhub中提到的3個擴展
Rust (rls)
C/C++
Native Debug
裝好后打開src/main.rs,修改為
fn main() { let mut a = 0; a = 3; a = 5; a = 10; println!("Hello, world!"); }
設置斷點選項,菜單 File > Preferences > Setting中搜索break,勾選Allow setting breakpoints in any file
關掉Rustup
回到main.rs文件,按F9設置斷點(也可能是我用了VS快鍵擴展),並且按Ctrl + Shift + B編譯Build
沒問題后按F5調試運行
F10單步觀察變量a變化,成功,完美收工
最后是拉倉庫
可以換成國內線路
到
C:\Users\你的用戶名\.cargo
目錄下創建config文件,沒有擴展名,寫入下面的內容,下載時能快一點。
[source.crates-io] registry = "https://github.com/rust-lang/crates.io-index" replace-with = 'ustc' [source.ustc] registry = "https://mirrors.ustc.edu.cn/crates.io-index"
========================================
經過1天時間發現,離線安裝雖然能用,但是按F12無法查看Rust標准庫源碼。
因為暫時也沒找到F12源碼的下載地址,直接下載rustc的源碼明顯對應不上,晚些時間再補個在線安裝版說明。