使用Git在Rust货物中添加依赖项时,是否可以使用路径
我想添加货物依赖项roughocet-okapi
作为git url,现在我添加了依赖项,例如cargo.toml
this:
rocket-okapi = { git = "https://github.com/GREsau/okapi/tree/master/rocket-okapi"}
但是当我使用构建项目时货物构建
命令,显示这样的错误:
$ 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中的依赖项?是否可以?
I want to add the cargo dependencies rocket-okapi
as git url, now I added the dependencies like in Cargo.toml
this:
rocket-okapi = { git = "https://github.com/GREsau/okapi/tree/master/rocket-okapi"}
but when I build the project using cargo build
command ,shows error like this:
$ 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)
how to add the sub folder as dependencies in rust cargo? is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里有几件事需要一些澄清。
当您将git依赖项添加到
cargo.toml
时,它会期望一个存储库。您放入的URL在存储库中有一个目录,因此货物
怪异。其次,当指定git依赖关系时,
货物
首先在存储库根中查看cargo.toml
文件。如果找不到任何东西,它将搜索任何cargo.toml
文件与依赖关系相同的文件。您指定的依赖性,
Rocket-Okapi
,在存储库中不存在,因此货物
放弃了。将依赖项的名称更改为“ Rocket_okapi”。TL; DR:使用此
There are a few things here that need a bit of clarification.
When you add a Git dependency to
Cargo.toml
, it expects a repository. The URL you put in there is a directory in the repository, socargo
freaks out.Secondly, when a Git dependency is specified,
cargo
first looks in the repository root for aCargo.toml
file. If it cannot find any, it will search for anyCargo.toml
files where the package name is the same as the dependency.The dependency you specified,
rocket-okapi
, doesn't exist in the repository, socargo
gives up. Changing the name of the dependency to 'rocket_okapi' fixes this.TL;DR: Use this