Updating crates.io index 出现错误解决方法

在向Rust项目添加依赖后尝试运行或编译,cargo管理工具会尝试更新crates.io index,当出现git配置错误可能会出现类似以下的错误:

update crates.io index
    Updating crates.io index
error: failed to get `rust-crypto` as a dependency of package `rust v0.1.0 (D:\hocn\Desktop\src\rust)`

Caused by:
  failed to load source for dependency `rust-crypto`

Caused by:
  Unable to update registry `crates-io`

Caused by:
  failed to fetch `https://github.com/rust-lang/crates.io-index`

Caused by:
  failed to authenticate when downloading repository: git@github.com:rust-lang/crates.io-index

  * attempted ssh-agent authentication, but no usernames succeeded: `git`

  if the git CLI succeeds then `net.git-fetch-with-cli` may help here
  https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli

Caused by:
  error authenticating: unable to connect to agent pipe; class=Ssh (23)

出现这样的错误,原因可能是本地crates.io index损坏,cargo尝试更新时,git的错误配置导致无法获取新的crates.io index

这里不讨论如何去配置git,只研究如何获取最新的crates.io index

解决方法

首先将rust更新到最新版,如果对版本有要求,可跳过这一步;

rustup update

运行命令 rustup update

然后找到C:\Users\xxxx\.cargo\registry目录(这里以Windows系统为例,xxxx是你的用户名);

进入index文件夹,你会看到一个这样的目录(名称可能不一样):

update crates.io index

该目录就是一个github仓库,远程地址为:https://github.com/rust-lang/crates.io-index

你要做的是将该目录的名称记录下来,这里是github.com-1ecc6299db9ec823,然后将该目录删除;

将github仓库克隆到该目录,你可使用git进行克隆,或直接下载仓库到本地;

update crates.io index

完成后将目录名替换成github.com-1ecc6299db9ec823,注意目录结构;

此时再运行或编译程序将不会再报错;

原创内容,如需转载,请注明出处;

本文地址: https://www.perfcode.com/p/updating-crates-io-index.html

分类: 计算机技术
推荐阅读:
Golang实现冒泡排序算法(Bubble Sort) 本文将使用Go语言完成冒泡排序算法(Bubble Sort)的实现;
一条Linux命令让你看起来很忙还很酷 在Linux系统下,如果你想让你的终端看起来很忙,或者想在某人面前装酷,那么你一定需要这条命令来实现:
PyQt:改变PyQt界面主题风格 Qt不仅功能强大、跨平台,还一个重要的因素是它生成的界面非常漂亮,且可以随意切换主题风格;本文将介绍如何使用Python获取当前系统支持的PyQt界面主题风格,以及如何切换使用它们;
WordPress去掉dns-prefetch 这段代码的作用是DNS预获取,当你网站有用到 s.w.org这个站点下的资源时,它能给我们提速,但实际上,国内几乎是用不上的。
使用vim编辑文件时添加密码保护 当你使用vim编辑器编辑一个文件时,可以使用一条命令即可实现向该文件添加一个密码保护;如果输入的密码错误,将无法正确打开文件,得到的是乱码;
解决Golang中cannot refer to unexported name xxxx这类错误 在Golang中,碰到cannot refer to unexported name xxxx,这类错误,通常是你调用了一个包内不存在的函数导致的;