溫課

Rust拉取庫文件時遇到spurious network error

官方英文链接 https://doc.rust-lang.org/cargo/reference/source-replacement.html

Rust编译时如果遇到如下问题:

Downloading futures v0.1.19
warning: spurious network error (2 tries remaining): [28] Timeout was reached (Operation timed out after 30857 milliseconds with 0 out of 0 bytes received)
error: unable to get packages from source

Caused by:
 [35] SSL connect error (OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to static.crates.io:443 )

解决办法:更换Crates源

Rust开发时, 即便网络牛X, 国外的源, 某些兄弟也连得上, 但笔者相信大多数情况下使用官方的源都太慢,建议您考虑更换使用国内中科大的源。更换方法如下:

先在控制台cd ~/.cargo然后vim config, 这样在 $HOME/.cargo/config文件当中添加如下内容:

[source.crates-io]
replace-with = 'ustc'

[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"

如果所处的环境中不允许使用 git 协议,可以把上述地址改为:

registry = "https://mirrors.ustc.edu.cn/crates.io-index"

精彩推薦

我要說兩句
網上嘉賓點評
(沙發已空)