如何让包裹使用与B相同的依赖项?

发布于 2025-02-01 01:07:13 字数 752 浏览 1 评论 0原文

我有一个像以下项目A和B的项目A和B,B取决于A。A是git子。

repo
|- contrib
|--- A
|----- components
|------- package A
|------- package B
|----- Cargo.toml
|- B
|--- Cargo.toml

A具有以下依赖性,

// A/Cargo.toml
serde = "1.0"
serde_derive = "1.0"
serde_ignored = "0.1"
serde_json = "1.0"
tempfile = "3.0"
lazy_static = "1.3"

我希望B具有相同的依赖项版本,例如A,

// B/Cargo.toml

compA = { path = "../A/components/compA" }
compB = { path = "../A/components/compB" }

serde = "1.0"
serde_derive = "1.0"
serde_ignored = "0.1"
serde_json = "1.0"
tempfile = "3.0"
lazy_static = "1.3"

但是如下,一旦A更新A,它可能会更新其依赖关系。因此,可以稍后使用serde =“ 2.0”。那么B“自动”如何将其SERDE更新为2.0?

我认为我需要一些说“ B取决于A取决于A的Serde”。

I have a project A and B like the following, B depend on A. A is a git submoudle.

repo
|- contrib
|--- A
|----- components
|------- package A
|------- package B
|----- Cargo.toml
|- B
|--- Cargo.toml

A have dependency like the following

// A/Cargo.toml
serde = "1.0"
serde_derive = "1.0"
serde_ignored = "0.1"
serde_json = "1.0"
tempfile = "3.0"
lazy_static = "1.3"

I want B have the same dependency version like A, like the following

// B/Cargo.toml

compA = { path = "../A/components/compA" }
compB = { path = "../A/components/compB" }

serde = "1.0"
serde_derive = "1.0"
serde_ignored = "0.1"
serde_json = "1.0"
tempfile = "3.0"
lazy_static = "1.3"

However, once A is updated, it may updates its dependencies. So A may use serde = "2.0" later. So how can B "automaticly" update its serde to 2.0?

I think I need something that says "B depends the serde which A is depending".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

早茶月光 2025-02-08 01:07:13

我认为我需要一些说“ b取决于a的serde”。

如果它们是同一货物工作区的一部分,那么(由于1.64),您应该使用工作区依赖关系

否则,a应公开/重新删除相关的板条箱(或其部分):

pub use serde; // etc

然后b应使用这些导出,而不是在其<<<<代码> CARGO.TOML :

use A::serde; // etc

I think I need something that says "B depends the serde which A is depending".

If they are part of the same Cargo workspace, then (since 1.64) you should use workspace dependencies.

Otherwise, A should expose/re-export the relevant crates (or parts thereof), for example:

pub use serde; // etc

and then B should use those exports rather than declaring each dependency in its Cargo.toml:

use A::serde; // etc
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文