Rust cargo镜像加速

  推荐使用科大的注册服务来提升拉取依赖的速度,地址:https://mirrors.ustc.edu.cn/help/crates.io-index.html

1.部分依赖镜像支持【也就是添加一个镜像地址,在拉取依赖的时候指定从哪个镜像地址获取】

  首先,cargo的配置文件地址位于系统的用户目录下的cargo目录,也就是 $HOME/.cargo/config.toml 【如果文件不存在则手动创建一下】

 

   配置该文件内容为:

[registries]
ustc = { index = "https://mirrors.ustc.edu.cn/crates.io-index/" }

  然后在项目的Cargo.toml中指定该镜像即可。

[dependencies]
time = {  registry = "ustc" }

2.全局镜像加速

  修改cargo的配置文件

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

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

  如果不支持git协议,可以改成http协议,推荐http。

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

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

 

posted @ 2022-11-19 12:12  SpringCore  阅读(1027)  评论(0编辑  收藏  举报