是否可以在使用git添加rust cargo中的依赖时使用该路径



我想添加货物依赖关系rocket-okapi作为git url,现在我添加了依赖关系像在Cargo.toml这样:

rocket-okapi = { git = "https://github.com/GREsau/okapi/tree/master/rocket-okapi"}

但是当我使用cargo build命令构建项目时,显示如下错误:

$ cargo build
Updating git repository `https://github.com/GREsau/okapi/tree/master/rocket-okapi`
warning: spurious network error (2 tries remaining): unexpected http status code: 404; class=Http (34)
warning: spurious network error (1 tries remaining): unexpected http status code: 404; class=Http (34)
error: failed to get `rocket-okapi` as a dependency of package `fortune v0.1.0 (/workspaces/fortune)`
Caused by:
failed to load source for dependency `rocket-okapi`
Caused by:
Unable to update https://github.com/GREsau/okapi/tree/master/rocket-okapi
Caused by:
failed to fetch into: /home/codespace/.cargo/git/db/rocket-okapi-b6c0b0836896ac76
Caused by:
network failure seems to have happened
if a proxy or similar is necessary `net.git-fetch-with-cli` may help here
https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli
Caused by:
unexpected http status code: 404; class=Http (34)

如何将子文件夹添加为rust cargo中的依赖项?这可能吗?

这里有几件事需要澄清一下。

当您向Cargo.toml添加Git依赖时,它需要一个存储库。您在这里输入的URL是存储库中的目录,因此cargo会出错。

其次,当指定Git依赖项时,cargo首先在存储库根目录中查找Cargo.toml文件。如果找不到,它将搜索任何与依赖项名称相同的Cargo.toml文件。

您指定的依赖项rocket-okapi在存储库中不存在,因此cargo放弃。将依赖项的名称更改为'rocket_okapi'可以修复此问题。

TL;DR:使用这个

rocket_okapi = { git = "https://github.com/GREsau/okapi" }

最新更新