最近发现rust居然被墙了,安装都装不了,不过还好可以配置代理。
==============================
Rust依赖库下载地址:
a.Docs.rs
b.crates.io: Rust Package Registry
c.github
==============================
【代理方法1】:发现使用中科大的镜像更快,在环境变量中加入以下两个:
变量名:RUSTUP_DIST_SERVER,变量值:https://mirrors.ustc.edu.cn/rust-static
变量名:RUSTUP_UPDATE_ROOT,变量值:https://mirrors.ustc.edu.cn/rust-static/rustup
【代理方法2】:在~/.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"
[http]
check-revoke = false
下载https://win.rustup.rs/之后再运行rustup-init.exe,放在D:\目录下即可。
1. cmd下安装步骤
set RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
set RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
d:\rustup-init.exe
2. powershell(注意不是cmd)
$proxy='http://127.0.0.1:1080'
$ENV:HTTP_PROXY=$proxy
$ENV:HTTPS_PROXY=$proxy
.\rustup-init.exe
3. 切换nightly
set RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
set RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
set PATH=%USERPROFILE%\.cargo\bin;%PATH%
rustup default nightly
4. 切换回stable
set RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
set RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
set PATH=%USERPROFILE%\.cargo\bin;%PATH%
rustup default stable
5. %USERPROFILE%\.cargo\目录下创建config文件(完成cargo更新代理)
[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/"
[http]
check-revoke = false
6. VSCode安装rust(rls)组件
Ctrl + P
ext install Rust (rls)
7. 安装组件
rustup.exe component add rust-analysis
rustup.exe component add rust-src
rustup.exe component add rls
cargo install racer
cargo install rustsym
cargo install rustfmt
8. 最佳实践
cargo install vendor
或
cargo install cargo-vendor
cargo new hello-world --bin
cd hello-world
cargo vendor
#生成文档(包含引用库的文档信息)
cargo doc --open