使用Git在Rust货物中添加依赖项时,是否可以使用路径

发布于 2025-02-05 18:18:20 字数 1249 浏览 3 评论 0原文

我想添加货物依赖项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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜无邪 2025-02-12 18:18:20

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

当您将git依赖项添加到cargo.toml时,它会期望一个存储库。您放入的URL在存储库中有一个目录,因此货物怪异。

其次,当指定git依赖关系时,货物首先在存储库根中查看cargo.toml文件。如果找不到任何东西,它将搜索任何 cargo.toml文件与依赖关系相同的文件。

您指定的依赖性,Rocket-Okapi,在存储库中不存在,因此货物放弃了。将依赖项的名称更改为“ Rocket_okapi”。

TL; DR:使用此

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

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, so cargo freaks out.

Secondly, when a Git dependency is specified, cargo first looks in the repository root for a Cargo.toml file. If it cannot find any, it will search for any Cargo.toml files where the package name is the same as the dependency.

The dependency you specified, rocket-okapi, doesn't exist in the repository, so cargo gives up. Changing the name of the dependency to 'rocket_okapi' fixes this.

TL;DR: Use this

rocket_okapi = { git = "https://github.com/GREsau/okapi" }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文