我想添加 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 中的依赖项?这可能吗?
最佳答案
这里有一些事情需要澄清。
当您将 Git 依赖项添加到 Cargo.toml
时,它需要一个存储库。您输入的 URL 是存储库中的一个目录,因此 cargo
会崩溃。
其次,当指定 Git 依赖项时,cargo
首先在存储库根目录中查找 Cargo.toml
文件。如果找不到任何文件,它将搜索包名称与依赖项相同的任何 Cargo.toml
文件。
存储库中不存在您指定的依赖项 rocket-okapi
,因此 cargo
放弃。将依赖项的名称更改为“rocket_okapi”可以解决此问题。
TL;DR:使用这个
rocket_okapi = { git = "https://github.com/GREsau/okapi" }
关于rust - 使用git添加rust Cargo中的依赖项时是否可以使用路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72528834/