我有一个箱子foo_sys
。在 Rust 2015 中我使用了extern crate foo_sys as foo
为了方便起见,但在 Rust 2018 中extern crate
不再需要,我不想仅将它用于别名。掉落时extern crate
, I get
error[E0463] https://doc.rust-lang.org/error-index.html#E0463: 找不到箱子foo
这可以通过以下方式实现重命名依赖 https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html?highlight=rename,depende#renaming-dependencies-in-cargotoml货物功能,Rust 1.31 中可用 https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html#cargo-features。通过此功能,可以为依赖项提供包属性:
重命名依赖项功能允许您导入与源名称不同的依赖项。这在某些情况下很有用:
- 取决于来自不同注册中心的同名板条箱。
- 取决于板条箱的多个版本。
- 避免需要
extern crate foo as bar
在 Rust 源码中。
而不是写作
[dependencies]
foo_sys = "0.2"
the package
key 可以添加到依赖项中Cargo.toml
:
[dependencies]
foo = { package = "foo_sys", version = "0.2" }
WARNING: Rust 1.26.0 之前的 Cargo 可能会下载错误的依赖项 https://github.com/rust-lang/rust/security/advisories/GHSA-phjm-8x66-qw4r使用此功能时!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)